jQuery AJAX状态“200 OK”,但没有数据响应,进入错误状态

时间:2013-11-28 08:14:48

标签: jquery oauth-2.0 google-oauth

我正在尝试从oauth2 redirect ui

收到的授权代码中获取访问令牌
$.ajax({
        dataType: "json",
        url:searchurl,
        data: {code:code, client_id:'clientid', client_secret:'secret', redirect_uri:'http://localhost:8085/mypro/getAccesstoken.jsp', grant_type:'authorization_code'},
        type:"POST",
        contentType:"application/x-www-form-urlencoded; charset=utf-8",
        crossDomain:true,
        cache : true, 
        success:function(data) {
            alert(data);
        },
        error: function(jqXHR, exception, errorstr) {
            console.log(jqXHR);
            alert(errorstr);
        }
    });

网址得到200 OK响应,但我根本没有得到回复

enter image description here

控制台出错:

Object { readyState=0, status=0, statusText="error", more...}

当我尝试设置请求标头Access-Control-Allow-Origin:*

beforeSend: function(xhr){xhr.setRequestHeader('Access-Control-Allow-Origin', '*');}, 

请求标题:

Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Access-Control-Request-He...    access-control-allow-origin
Access-Control-Request-Me...    POST
Cache-Control   no-cache
Connection  keep-alive
Host    accounts.google.com
Origin  http://localhost:8085
Pragma  no-cache
User-Agent  Mozilla/5.0 (Windows NT 6.2; rv:25.0) Gecko/20100101 Firefox/25.0

我收到错误

"NetworkError: 405 Method Not Allowed - https://accounts.google.com/o/oauth2/token"

0 个答案:

没有答案