Reputation: 2500
I'm new to AJAX and trying to figure out how to do a JSONP cross-domain call. I'm not exactly sure what is wrong with the following code. In the Firebug NET console I can see the response just fine (full HTML page), and the HTML tab shows up fine also. I'm getting a "syntax error" that's pointing to the URL /?jsonp=jQuery17109722891130251606_1345069208686&_=1345069209298.
I had an error section in there, but just read that error functions inside of the .ajax don't work correctly when using JSONP?
Here's the code:
$.ajax({
url: 'http://www.google.com',
type: 'GET',
dataType: 'jsonp',
jsonp: 'jsonp',
crossDomain: true,
complete:function(jsonp){
$('#test').append(jsonp);
}
});
I'm running this locally, have tried different URLs.... any ideas or explanations? Thanks! Forgot to mention that the textStatus is also throwing a parsererror?
Upvotes: 1
Views: 70
Reputation: 2565
In here
complete:function(jsonp){
$('#test').append(jsonp);
}
you are trying to append a jqXHR
object to a DOM element. Look at this: http://jsfiddle.net/TkUBz/
What you need to do is to use the success
property, as in:
/*complete*/
success:function(data){
$('#test').append(data);
}
Now, the syntax error that you see is because you're loading google's
front page, which contains a javascript code, which the browser tries to execute when it appends the HTML data to the #test
element and that javascript code won't work on your page for different reasons, therefore the code fails and you see a syntax error.
Upvotes: 2