jquery ajax请求跨域时返回状态码0

2024-01-07

我正在尝试发出跨域请求,但服务器无法响应

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);
        });

提前致谢


你尝试过吗这个jquery跨域 https://github.com/padolsey/jQuery-Plugins/tree/master/cross-domain-ajax/插入?

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

$.ajax({
   url: "https://accounts.google.com/o/oauth2/auth",
   type: "POST",
   dataType: 'jsonp',
   ...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jquery ajax请求跨域时返回状态码0 的相关文章