0

I'm trying to use the jQuery get function to render the results of an HTML page in a div on my page. The result of the get function appears to be successful because the value of textStatus (in the following code block) is "success". The value of data, however, is always empty.

$(document).ready(function() {
  $.get('http://www.google.com', function(data, textStatus){
    $('#RSSContent').html(textStatus + ' ' + data);
  });
});

Any idea what I might be doing wrong?

Note: The final code will query a GeoRSS feed, which I plan on transforming and rendering as HTML in the RSSContent div. I simply used http://www.google.com for testing purposes.

1
  • 1
    What's the dataType you're going to be using? Try specifying it. Try using Firebug to look at the actual XmlHttpRequest. Because of XSS issues, if your dataType is (going to be) XML (rather than JSON or script) the server you're $.get-ing from must be in the same domain. Commented Apr 5, 2010 at 15:49

1 Answer 1

3

You can't make an AJAX request to another domain like this. What you're running into is called the same origin policy. For security reasons, javascript isn't allowed to make a request like this (except in certain cases like JSONP).

Imagine if my ad script in your page (via document.write or any XSS method) was able to copy your name and password fields and submit it to another domain in the background via AJAX...bad idea :)

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

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.