2013-02-18 67 views
0

我试图让跨域请求,但服务器无法响应与jQuery的AJAX返回状态码0,而请求跨域

Access-Control-Allow-Origin: * 

我想读响应头。 当我试图读取状态码或就绪状态时,它返回0.我的代码为ajax请求如下。

$.ajax({ 
     url: "https://accounts.google.com/o/oauth2/auth", 
     type: "POST", 
     data: {"response_type":"token","client_id":"6720XXXXXXX.apps.googleusercontent.com","redirect_uri":"http://localhost:51967/oauth2callback.aspx","scope":"https://www.googleapis.com/auth/calendar","state":"this is state information","approval_prompt":"auto"},    
       crossDomain: true 
     }).always(function(jqxhr,testStatus,errorThrown) 
     { 
       alert(jqxhr.readyState); 
       alert(jqxhr.status); 
     }); 

在此先感谢

回答

0

你尝试this jquery crossdomain插件?

另一种方式是使用作为jsonp响应类型

$.ajax({ 
    url: "https://accounts.google.com/o/oauth2/auth", 
    type: "POST", 
    dataType: 'jsonp', 
    ... 
+0

那么服务器将返回400错误使用时JSONP它发送其他数据,诸如回调= jQuery19009566406458362526_13611668XXX因为它仅接受一定的数据作为交 – 2013-02-18 06:03:53