Jsonp cross-domain ajax

Posted by Guillaume le Floch on Stack Overflow See other posts from Stack Overflow or by Guillaume le Floch
Published on 2012-09-06T03:26:18Z Indexed on 2012/09/06 3:38 UTC
Read the original article Hit count: 226

Filed under:
|
|
|

I'm working on an application which use ajax call to get html from the server. When I run it on the server, everything works fine.

But when I'm running on a localhost, I've a 'Access-Control-Allow-Origin' error. I looked arround and it seems like using jsonp could be the solution.

So, my ajax call looks like that:

$.ajax({
    url: url,
    dataType: 'jsonp',
    crossDomain: true,
    type: 'GET',
    success: function(data){
        // should put the data in a div
    },
    error: function(){
        //do some stuff with errors
    }
});

I get html from the server, but I always have this error:

Uncaught SyntaxError: Unexpected token < 

Is there a way to wrap the jsonp response in html?

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery