WP7 Phonegap使用YQL从跨域url下载xml

时间:2012-01-19 23:02:02

标签: windows-phone-7 cordova

以下代码适用于我的电脑上的firefox,chrome和IE9。 但是当我使用phonegap在WP7设备中运行它时,回调函数不会返回。

function downloadXML(
$.ajax({
    async: true,
    cache: false,
    type: 'GET',
    dataType: "xml",
    crossDomain: true,
    url: yql_url('http://some-cross-domain-url'),
    error:function(xhr, status, errorThrown){
            navigator.notification.alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
        },
    success: function (xml) {
            navigator.notification.alert("successful");
        }
    });
    }
    yql_url = function(source_url) {
    return "http://query.yahooapis.com/v1/public/yql?q=select * from xml where url=\"" + source_url + "\"";
    }

有没有人指出EXTRA必须做什么才能让它在WP7上运行? THX

或者让我重新构建问题,

有人可以给我一个代码片段,该代码片段适用于带有phonegap的WP7,可以从跨域URL获取XML。 我一直在努力让它在WP7上运行而没有任何成功:(

2 个答案:

答案 0 :(得分:0)

似乎与Phonegap for Windows Phone jQuery ajax callback not executed

相似

请尝试以下操作:评论phonegap-1.3.0.js中从3551行开始到文件末尾的所有内容

//(function(win,doc){
//
//    doc.addEventListener("DOMContentLoaded",function()
//    { 
// ......
//      if(!docDomain || docDomain.length == 0)
//      {
//          //console.log("adding our own Local XHR shim ");
//          var aliasXHR = win.XMLHttpRequest;
//      
//          win.XMLHttpRequest = function(){};
//      
//          var UNSENT = 0;
// ......
//
//    
//})(window,document);

PS。对于WP7上的XSS,您还需要jQuery的以下标志 $ .support.cors = true;

修改 PhoneGap 1.4.0rc1已提交

https://github.com/purplecabbage/callback-windows-phone

更改包括修复XHR到本地文件,+修复以允许jQM单/多用途应用程序正常运行。

答案 1 :(得分:0)

您需要将以下内容设为true:

$。support.cors 和 $ .mobile.allowCrossDomainPages

检查jQuery Mobile Docs