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){
$('#RSSCon开发者_Python百科tent').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.
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 :)
精彩评论