我正在尝试从 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;
});