科尔多瓦CORS调用不工作 [英] Cordova CORS call not working

查看:137
本文介绍了科尔多瓦CORS调用不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么,但我的CORS调用是行不通的。

I don't understand why, but my CORS call is not working.

我添加了元标记的index.html

I added the meta tag to index.html

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

我的Andr​​oid清单有:

my android manifest has:

 <uses-permission android:name="android.permission.INTERNET" />

我的电话的标题是:

the headers of my call are :

Access-Control-Allow-Headers → Content-Type
Access-Control-Allow-Methods → GET,PUT,POST,DELETE
Access-Control-Allow-Origin → *

在我的config.xml中,我有

In my config.xml i have

 <access origin="*" />
 <plugin name="cordova-plugin-whitelist" version="1" />

和我的code是

 var request = new XMLHttpRequest();
 request.open("GET", "http://XXXXXXXXXX/XXXXX", true);
console.log("test");
request.onreadystatechange = function () {
   console.log("DOES NOT COME HERE?")
    if (request.readyState == 4) {
        if (request.status == 200 || request.status == 0) {
            alert(code);
            var product = JSON.parse(request.responseText);
            alert(product.CNK);
        }
    }

不来这里不打印,也没有在日志中输出了错误?我真的不知道我做错了什么:(

"DOES NOT COME HERE" doesn't get printed, also no error printed in the log? I really don't know what I'm doing wrong :(

推荐答案

确定的解决方案是很愚蠢的,我搜索的方式来长了

OK the solution was so stupid, I searched way to long for this

var request = new XMLHttpRequest();
request.open("GET", "http://XXXXXXXXXX/XXXXX", true);
console.log("test");
request.send()
request.onreadystatechange = function () {
console.log("DOES NOT COME HERE?")
if (request.readyState == 4) {
    if (request.status == 200 || request.status == 0) {
        alert(code);
        var product = JSON.parse(request.responseText);
        alert(product.CNK);
    }
}

正如你看到我添加request.send())

As you see I added request.send() :)

这篇关于科尔多瓦CORS调用不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆