Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cordova应用程序中的Ajax请求&x27;s_Cordova - Fatal编程技术网

cordova应用程序中的Ajax请求&x27;s

cordova应用程序中的Ajax请求&x27;s,cordova,Cordova,我正在使用cordova。我想在我的应用程序中使用$.ajax jquery请求。这是我的“内容安全策略”元标记: <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src 'self' ht

我正在使用cordova。我想在我的应用程序中使用$.ajax jquery请求。这是我的“内容安全策略”元标记:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src 'self' http://localhost">
单击链接后,我看到此错误:

index.html:1未能加载 :没有 “Access Control Allow Origin”标头出现在请求的服务器上 资源。因此,不允许使用源“” 进入


我的问题在哪里?

将其添加到PHP文件的第一行<代码>标题('Access-control-allow-origin:')


查看更多详细信息。基本上,服务器不信任该请求,因此拒绝该请求。通过设置CORS,您可以允许所有请求

我更改了script.js文件,现在一切正常

$('#get_web_data').on('tap',function(){
        $.ajax({
            url:'http://localhost/test.php',
            type:'GET',
            data:{'user_name':'amir','password':'123'},
            dataType:'json',
            timeout: 5000,
             crossDomain: true,
              error: function (jqXHR, textStatus, errorThrown) {
                alert('new textStatus=' + textStatus + ' errorThrown=' + errorThrown);
            },
            success: function (response) {alert(response);
    }
        }) ;
     });
 $('#get_web_data').on('tap',function(){
        $.ajax({
            url:'http://localhost/test.php',
            type:'GET',
            data:{'user_name':'amir','password':'123'},
            dataType:'json',
            success:function(data){
                alert(data);
            },
            error:function(error){alert('Error');}
        }) ;
     });
$('#get_web_data').on('tap',function(){
        $.ajax({
            url:'http://localhost/test.php',
            type:'GET',
            data:{'user_name':'amir','password':'123'},
            dataType:'json',
            timeout: 5000,
             crossDomain: true,
              error: function (jqXHR, textStatus, errorThrown) {
                alert('new textStatus=' + textStatus + ' errorThrown=' + errorThrown);
            },
            success: function (response) {alert(response);
    }
        }) ;
     });