Phonegap跨域问题

3
我正尝试从Phonegap打开并读取一个XML文件,但出现了CORS错误。我该如何解决?
XMLHttpRequest cannot load file://localhost/../data/file.xml. Origin null is not allowed by Access-Control-Allow-Origin.

调用者的代码是:
var request = $.ajax({
    type: "GET",
    url: "data/file.xml",
    async: false,
    dataType: "xml"
  });

由于这里的解释,我在我的代码中也有这段片段:

$(document).on( "mobileinit", function() {

           $.support.cors = true;
           $.mobile.allowCrossDomainPages = true;

           });
1个回答

1

您需要修改您的PhoneGap设置以允许访问localhost。

有几个文件需要查看,因此请参见gist和其他stackoverflow帖子。

请注意,这些示例适用于Android; 对于iPhone而言,问题相同,只是文件不同。


很遗憾,它没有帮助。 - noway

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接