简体   繁体   中英

How can i send cross domain ajax request with JSON response?

Guys,

I want to send a cross domain ajax request( http://dict.qq.com/dict?q=language ), but the server only provides JSON( Not JSONP ) response, is there anyway to make the request ?

Here's what i've did:

$.ajax({
    url:"http://dict.qq.com/dict?q=language",
    dataType:"jsonp",
    type:'get',
    processData:false,
    crossDomain:true,
    contentType:"application/json",
    success:result
});

function result(data){console.log(data);}

The response is :

Uncaught SyntaxError: Unexpected token : 

Thanks !

还需要将服务器配置为允许跨域请求,例如:

  Http.Response.current().accessControl("*", "GET,PUT,POST,DELETE,OPTIONS",false);

Generally the same origin policy prevents you from doing so. If you have access to the other server you can attempt to change the http headers sent to circumvent this. Here's a tutorial for using CORS (Cross-Origin Resource Sharing) to achieve this.

If you have no control over the remote server perhaps you can try using a server-side proxy such as this one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM