2016-04-22 228 views
0

我正在构建Phonegap应用程序,并且我为iOS平台安装了插件WKWebViewWKWebView xhr在phonegap项目中返回状态0并且readyState = 4

,我现在面临的问题是,当我使用xhr谷歌从代码获得访问令牌做出post我得到xhr回报readyState = 4status = 0

如果我测试使用UIWebView使用相同的代码一切工作正常。 Android(没有WKWebView)也是相同的代码工作正常。所以,这个问题仅是使用WKWebView

这里iOS是后:

var xhr = new XMLHttpRequest(); 
    var url = "https://accounts.google.com/o/oauth2/token"; 
    var data = 'code=' + encodeURIComponent(code[1]) + 
       '&client_id=' + encodeURIComponent(this.gdrive_client_id) + 
       '&client_secret=' + encodeURIComponent(this.gdrive_client_secret) + 
       '&redirect_uri=http%3A%2F%2Flocalhost' + 
       '&grant_type=authorization_code' 
    xhr.open("POST", url, true); 
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 

    xhr.send(data); 
    xhr.onreadystatechange = function() { 
     if (xhr.readyState == 4) { 
      console.log(xhr.status); //Here I get status 0 
     } 
    }; 

我使用WKWebView verison 0.6.4

Phonegap CLI版本5.5.2

平台:IOS 3.9.2

回答

0

WKWebVie与webview不同,w实际上尊重了跨源请求策略。这实际上更安全,但是由于种种原因,对于phonegap/cordova应用程序来说是一件麻烦事。有关详细信息,请参阅this issueamongstothers

相关问题