【发布时间】:2011-11-25 14:18:54
【问题描述】:
我正在 PhoneGap+dreamweaver cs5.5 中开发一个应用程序,它调用处理程序 (.ashx) 并返回一个 JSON 字符串。我执行以下操作:
function appReady(){
var ajax = new XMLHttpRequest();
ajax.open("GET","https://xxxx.xxxxx.com/xxxx/xxxx.ashx?method=GetUser&email=xxx@xxxx.com&pwd=123456",false);
ajax.send();
ajax.onreadystatechange=function(){
if(ajax.readyState == 4) {//Request complete !!
if (ajax.status == 200 || ajax.status == 0) { // OK response
alert(ajax.responseText);
document.getElementById('main').innerHTML = ajax.responseText;
}
}
}
}
当我在 iphone 模拟器上运行应用程序时,我恢复了 json 字符串 responseText,但在 android 模拟器上这是空的。在 iphone 中返回的状态是 200,但在 android 中是 0。 如果问题是 coss-domain 请求,那么在任何平台上都不起作用吗?
不明白为什么wiki的例子:http://wiki.phonegap.com/w/page/42450600/PhoneGap%20Ajax% 20Sample
在两个平台上都可以正常工作,而我的只能在 iphone 上运行 ...
【问题讨论】:
-
在分配就绪状态处理程序后尝试
send()。
标签: javascript android iphone ajax cordova