【问题标题】:Cross-Origin Resource Sharing (cors) ajax request not working on mobile device跨域资源共享 (cors) ajax 请求在移动设备上不起作用
【发布时间】:2014-03-14 10:47:45
【问题描述】:

我正在使用 jQuery mobile 和 phonegap 开发一个应用程序。以下是我的 phonegap、phonegap-1.1.0.js、jquery-1.7.1.js、jquery.mobile-1.4.1.min.js 的版本,从开发应用程序我正在调用具有 PHP 网站的其他主机的 Ajax 请求.

在我设置的那个服务器上 header('Access-Control-Allow-Origin: *'); 并在 Js 文件中定义 $.support.cors = true; $.mobile.allowCrossDomainPages = true;

我正在本地系统上使用 chrome 浏览器测试这个应用程序,一切正常,我得到了响应。但是当我使用 https://build.phonegap.com 为 android 和 ios 生成构建时。 cors Ajax 请求不起作用

下面是我调用的ajax代码

 $.ajax({
    type       : "POST",
    url        : // Other server url
    data       : {
        fId:'42'
    },
    dataType   : 'json',
    success    : function(response) {

    },
    error      : function(response) {
            // Response is coming in this case                 
    }
});`

谁能告诉我需要设置哪些设置

谢谢,

【问题讨论】:

    标签: android jquery ajax jquery-mobile cordova


    【解决方案1】:

    将以下行添加到您的 config.xml:

    <access origin="*" />
    

    http://docs.phonegap.com/en/3.4.0/guide_appdev_whitelist_index.md.html#Whitelist%20Guide

    【讨论】:

      猜你喜欢
      • 2016-03-14
      • 2013-01-12
      • 2020-12-16
      • 2018-05-04
      • 2017-10-06
      • 2014-01-18
      • 2014-10-08
      • 2014-03-20
      相关资源
      最近更新 更多