Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 How to grab html of a given link without having, CORS issue

views
     
TSGrammar Police
post Dec 31 2018, 10:58 AM, updated 6y ago

Casual
***
Junior Member
332 posts

Joined: Mar 2016
I tried using jquery

CODE

$.ajax({ url: 'your-url', success: function(data) { alert(data); } });


but it wont work as the website is not on my domain hence web security blocked that.

error code in chrome : Access to XMLHttpRequest at 'https://.xxx' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
eek-1
post Jan 2 2019, 12:59 AM

Custom member title
*****
Senior Member
776 posts

Joined: Jan 2003
From: Polysiloxanes Boulevard



Maybe curl at your server side and then send out to your ajax?
TSGrammar Police
post Jan 2 2019, 03:59 PM

Casual
***
Junior Member
332 posts

Joined: Mar 2016
QUOTE(eek-1 @ Jan 2 2019, 12:59 AM)
Maybe curl at your server side and then send out to your ajax?
*
i dont have a server

just me and my local machine.

This post has been edited by Grammar Police: Jan 2 2019, 05:14 PM
bumpo
post Jan 2 2019, 06:41 PM

On my way
****
Junior Member
632 posts

Joined: Mar 2013


there is simply no way to do it with ajax call. browser will specifically blocks it as part of security, although if you check via developer mode, you can see the response back from server is perfect.
depending on what you are doing.. one alternative is to use iframe. load the html via it then get the content from it
cubiclecarbonate
post Jan 3 2019, 09:43 AM

On my way
****
Junior Member
557 posts

Joined: Jul 2011


QUOTE(Grammar Police @ Dec 31 2018, 10:58 AM)
I tried using jquery

CODE

$.ajax({ url: 'your-url', success: function(data) { alert(data); } });


but it wont work as the website is not on my domain hence web security blocked that.

error code in chrome : Access to XMLHttpRequest at 'https://.xxx' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
*
if php, maybe you can try something like simple html dom parser
olumis
post Jan 6 2019, 11:35 AM

Getting Started
**
Junior Member
54 posts

Joined: Oct 2016
From: Tambunan, Sabah


with client's browser, impossibru. You'll need to fetch the remote contents and complete the task on the server side first then only push the end result to the client.
koklimabc
post Jan 8 2019, 09:02 AM

New Member
*
Junior Member
8 posts

Joined: Dec 2009


put the cross domain to avoid block,

$.ajax({ url: 'your-url', crossDomain: true, success: function(data) { alert(data); } });
TSGrammar Police
post Jan 8 2019, 09:25 AM

Casual
***
Junior Member
332 posts

Joined: Mar 2016
QUOTE(koklimabc @ Jan 8 2019, 09:02 AM)
put the cross domain to avoid block,

$.ajax({ url: 'your-url', crossDomain: true, success: function(data) { alert(data); } });
*
wahhh can ar? later i try
ex.luffy
post Jan 14 2019, 01:03 PM

New Member
*
Newbie
12 posts

Joined: Jul 2013
QUOTE(Grammar Police @ Jan 2 2019, 03:59 PM)
i dont have a server

just me and my local machine.
*
Use standalone local server.
brkli
post Jan 18 2019, 03:32 PM

On my way
****
Junior Member
539 posts

Joined: Oct 2018
for production use, better to do a proxy (in your domain) to the remote server. any web server like nginx or apache can do it. you do not need to use any programming for this.

for testing, you can always disable browser cross origin checking.

 

Change to:
| Lo-Fi Version
0.0129sec    0.26    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 07:31 AM