WP7 Phonegap使用YQL从跨域url下载xml
以下代码适用于我电脑上的 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 + "\"";
}
有人指出需要做哪些额外工作才能使其在 WP7 上运行吗?谢谢
,或者让我重新构建这个问题,
有人能给我一个在 WP7 上工作的代码片段,它带有phonegap,可以从跨域 URL 获取 XML。 我一直在尝试让它在 WP7 上运行但没有成功:(
the following code works on firefox,chrome and IE9 on my PC.
But the callback function doesn't return when I run it in WP7 device using phonegap.
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 + "\"";
}
Does anyone point out what EXTRA has to be done to make it run on WP7 ? THX
OR let me re-frame the question,
Can someone give me a code snippet which works on WP7 with phonegap that can fetch XML from a cross domain URL.
I have been trying a lot to make it run on WP7 without any success :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将以下内容设置为 true:
$.support.cors
和
$.mobile.allowCrossDomainPages
检查 jQuery Mobile 文档
You need to set the following to true:
$.support.cors
and
$.mobile.allowCrossDomainPages
Check the jQuery Mobile Docs
似乎类似于 Phonegap for Windows Phone jQuery ajax 回调不执行
尝试以下操作:注释phonegap-1.3.0.js中从第3551行到PS文件末尾的所有内容
。对于 WP7 上的 XSS,您还需要以下 jQuery 标志 $.support.cors = true;
EDIT
PhoneGap 1.4.0rc1 已提交
https://github.com/purplecabbage/callback-windows-phone< /a>
更改包括对本地文件的 XHR 的修复,以及允许 jQM 单/多页面应用程序正常运行的修复。
Seems to be similar to Phonegap for Windows Phone jQuery ajax callback not executed
Try the following: comment everything in phonegap-1.3.0.js starting from line 3551 to the end of the file
PS. For XSS on WP7 you also need the following flag for jQuery $.support.cors = true;
EDIT
PhoneGap 1.4.0rc1 is commited
https://github.com/purplecabbage/callback-windows-phone
Changes include fixes for XHR to local files, + fixes to allow jQM single/multipage apps function correctly.