gpt4 book ai didi

javascript - phonegap XMLHttpRequest responseText 在 android 中为空,但在 iphone 中包含数据

转载 作者:行者123 更新时间:2023-12-02 19:58:44 24 4
gpt4 key购买 nike

我正在 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 上工作......

最佳答案

检查跨域脚本问题。我做了几乎同样的事情,只是我的 URL 实际上位于同一个域中。它在 Android 和 PC 上运行良好,但 iPhone 无法运行。当我从 ' https://whatever.whatever.com/foo.asp 更改时' 到 foo.asp - 它成功了!

var rootpath;
rootpath = "https://the.same.dam.place/foo.asp"; // did not work!
rootpath = "foo.asp"; // shortening it worked.
function read_foo(whatever)
{
var url = rootpath + "?whatever=" + whatever;
xmlHttp = GetXmlHttpObject(stateChanged);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
var return_place = document.getElementById('return_place');
var thetext = xmlHttp.responseText;
return_place.innerHTML= thetext;
}
}

另请参阅:

Empty responseText from XMLHttpRequest

关于javascript - phonegap XMLHttpRequest responseText 在 android 中为空,但在 iphone 中包含数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8270385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com