1

I'm making an Get call for the URL http://google.com to get the html content of the site, But on the ajax call I'm ending up with the following 2 errors,

Error : GET http://www.google.com/ undefined (undefined)

Error : XMLHttpRequest cannot load google.com. Origin "URL of my local website" is not allowed by Access-Control-Allow-Origin.

Code for 1st error:

$.ajax({
    type : "GET",
    cache : false,
    url : url,
    dataType : "xml",
    crossDomain : true,
    contentType : "text/html",
    success : function(data){
        alert("success");
    },
    error : function(error){
        alert("error");
    }
});

Code for 2nd error:

$.ajax({
    url : url,
    dataType : "text",
    success : function(data){
        alert("success");
    },
    error : function(error){
        alert("error");
    }
});

What settings i need to make to enable the cross domain call,Help would be really appreciated.

I have also tried setting up $.mobile.allowCrossDomainPages = true and $.support.cros = true; before the ajax even this didn't work. Solution would be really appreciated.

2
  • You can do that using a third-party app (that uses server get requests). Commented Mar 26, 2014 at 7:14
  • See this question for a relevant answer. You will likely need to have a URL on your server you can call that will return you Google's HTML. Commented Mar 26, 2014 at 7:15

2 Answers 2

1

Long time ago I created a project that solves this issue. It's open source on GitHub

  $.ajax({
    url: 'http://google.com', // Or your web page link
    type: 'GET',
    success: function(res) {
      var headline = res.responseText;
      htmlCodeTextArea.value = headline;
    }
  });

To download it use:

git clone [email protected]:IonicaBizau/jQuery-cross-domain-requests.git

or click here.

Then open index3.html file.

Sign up to request clarification or add additional context in comments.

1 Comment

@KyleK It's still working for me. For questions/bug reports open issues here.
0

You are doing a cross-domain request which is blocked by most browsers as a security measure. You can only request content from same domain as the script is running, or need the server to recognize your domain and allow the cross-domain request via Access-Control-Allow-Origin header.

See more info on this at: http://en.wikipedia.org/wiki/Same_origin_policy

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.