Phonegap黑莓5跨域通信
我在 OS6 和 OS7 设备上测试了我的应用程序,两者都运行良好。但几天前,我在 OS5 设备上遇到了一个问题。所有 Ajax 请求均无效。经过一番谷歌搜索后,我发现在 OS5 中,ajax 被禁用了。这很奇怪,我的应用程序必须在 OS5 设备上运行,但我无法进行 Ajax 调用。
为了解决这个问题,我搜索了旧的跨域方法并找到了“动态脚本”和“IFrame”方法。这是一篇描述它们的文章:
http://www.openjs.com/articles/ajax/ Transfer_methods_xmlhttprequest_alternatives.php
但我没有关于非 xmlHttpRequest 或非 ActiveX 方法的示例。有没有人有关于这些方法的有效示例。我的服务器上有一个 jsp 文件,它向我发送 xml 响应。
一个可行的例子会让我非常感激。
提前致谢。
[编辑]
我决定使用 IFrame 进行跨端通信,但无法获取 iFrame 的内容,我的代码是这样的:
function onIFrameLoad(i) {
var response;
if(i.contentDocument){
response = i.contentDocument; // For NS6
}else if(i.contentWindow){
response = i.contentWindow.document; // For IE5.5 and IE6
}
var parser = new PListParser();
var result = parser.parsePList(response);
....
}
这
<iframe id="iFrame" onload="onIFrameLoad(this);" src="[a url]"></iframe>
在 Ripple 模拟器中运行良好,但在真实设备(os5)上不起作用。
I tested my app on OS6 and OS7 devices, both worked well. But a few days ago, I faced an issue on OS5 devices. All Ajax requests didn't work. After some googling, I found out that in OS5, ajax is disabled. It is so weird, My app must work on OS5 devices but I can't make Ajax call.
To fix this issue, I searched about old cross-domain methods and found 'dynamic scripting' and 'IFrame' methods. Here is an article describes them :
http://www.openjs.com/articles/ajax/transfer_methods_xmlhttprequest_alternatives.php
But I have no example about non xmlHttpRequest or non ActiveX methods. Is there anybody who has a working example about these methods. I have a jsp file on the server that sends me a xml response.
a working example will make me so grateful.
Thanks in advance.
[EDIT]
I decided to use IFrame to cross-side communication, but unable to get content of iFrame, my code is like that :
function onIFrameLoad(i) {
var response;
if(i.contentDocument){
response = i.contentDocument; // For NS6
}else if(i.contentWindow){
response = i.contentWindow.document; // For IE5.5 and IE6
}
var parser = new PListParser();
var result = parser.parsePList(response);
....
}
and
<iframe id="iFrame" onload="onIFrameLoad(this);" src="[a url]"></iframe>
this works well in Ripple Emulator but doesn't work on real device(os5).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否有权访问正在获取数据的服务器?如果这样做,也许您可以将其配置为以 JSONP 形式获取数据。
Do you have access to the server where you are fetching the data? If you do, maybe you could configure it to fetch the data as a JSONP.