无法与科尔多瓦发送跨域请求。白名单不工作科尔、名单、多瓦、工作

2023-09-04 03:05:18 作者:遥远的他

我无法通过科尔多瓦进行跨域请求。花了几个小时就这个问题和仍然不知道什么是错的。也许有人已经处理了这样的问题呢?谢谢!

js文件:

  //工作正常,test.html的 - 本地文件
  $获得(test.html中功能(数据,状态){
    警报(数据:+数据+\ n状态:+状态);
  });

//什么都不做
  $获得(http://www.stackoverflow.com功能(数据,状态){
    警报(数据:+数据+\ n状态:+状态);
  });
 

项目配置文件:

  ..
<获得原产地=stackoverflow.com/>
..
 

也尝试过:

 <获得原产地=www.stackoverflow.com/>
 <获得原产地=htt​​p://www.stackoverflow.com/>
 <获得原产地=*/>
 
react通过axios发送请求并演示配置多个反向代理地址解决跨域

的Andr​​oidManifest.xml:

  ..
<使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
..
 

解决方案

我有同样的问题......经过一番研究,我发现了一个办法做到这一点。 使用jQuery的$就做一个GET请求。 (在现实中,我试图访问一个SOAP WebService的,后来我发现这种方式使用POST或GET请求) 测试在这里的的jsfiddle 。 你仍然需要访问的起源虽然... 观测:您的请求将无法工作,除非你的网页正在试图让,让你做到这一点。示例页面允许访问,所以,尽量从科尔多瓦的应用程序访问它。的

  $。阿贾克斯({
            键入:GET,
            网址:http://anytime.ueuo.com/http-return.php
            跨域:真正的,
            成功:功能(数据,textStatus,jqXHR){
                警报(OK!);
                $(#RETORNO)的HTML(数据);
            },
            错误:函数(jqXHR,textStatus,errorThrown){
                警报(等一等,看一看+ textStatus +,+ errorThrown);
            },
            完成:功能(jqXHR,textStatus){
                警报(状态:+ textStatus);
            }
        });
 

OBS-2:你的code返回错误: XMLHtt prequest无法加载 http://www.stackoverflow.com/ 。 否访问控制 - 允许 - 原产地标头的请求的资源present。产地 HTTP ://本地主机:8383 ,因此不允许访问。 (02:18:52:813 |错误,javascript中)在的public_html / index.html的的。这就是为什么你需要测试以pre-配置页面。 对不起,我的坏英语 - 的

I cannot make cross domain request using Cordova. Spent several hours on this and still not sure what is wrong. Maybe someone has dealt with problem like this? Thanks!

.js file:

//works fine, test.html - local file
  $.get("test.html",function(data,status){
    alert("Data: " + data + "\nStatus: " + status);
  });

//does not do anything
  $.get("http://www.stackoverflow.com",function(data,status){
    alert("Data: " + data + "\nStatus: " + status);
  });

Project Config file:

..
<access origin="stackoverflow.com"/>
..

Also Tried:

 <access origin="www.stackoverflow.com"/>
 <access origin="http://www.stackoverflow.com"/>
 <access origin="*"/>

AndroidManifest.xml:

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

解决方案

I was having the same problem... after some researches I found a way to do this. Use the jQuery $.ajax to make a "GET" request. (In reality, I was trying to access a SOAP WebService, then I found this way to use a POST or GET request) Test here in the JSFiddle. You still need the access origin though... Obs: Your request will not work, unless the page you are trying to get, allow you to do this. The example page allow the access, so... try accessing it from your Cordova app.

$.ajax({
            type: 'GET',
            url: "http://anytime.ueuo.com/http-return.php",
            crossDomain: true,
            success: function (data, textStatus, jqXHR) {
                alert("Ok!");
                $("#retorno").html(data);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert("Wait, take a look: " + textStatus + ", " + errorThrown);
            },
            complete: function (jqXHR, textStatus ) {
                alert("Status: " + textStatus);
            }
        });

Obs-2: Your code return the error: XMLHttpRequest cannot load http://www.stackoverflow.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8383' is therefore not allowed access. (02:18:52:813 | error, javascript) at public_html/index.html. That's why you need to test with a pre-configured page. Sorry for my bad-english '-'