PhoneGap的XMLHtt prequest responseText的空与Android,但包含iphone数据 [英] phonegap XMLHttpRequest responseText empty with android but contain data in iphone
问题描述
我正在开发中的PhoneGap + Dreamweaver的CS5.5,谁使调用处理程序(ashx的),并返回一个JSON字符串的应用程序。我做到以下几点:
I'm developing an app in PhoneGap+dreamweaver cs5.5, who makes a call to a handler (.ashx) and returns a JSON string. I do the following:
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域的请求,也不会在任何平台上的工作权利?
When I running the app on the iphone emulator, I recover the json string responseText, but this comes empty on android emulator. In iphone the status returned is 200 but in android is 0. if the problem was the coss-domain request, wouldn't work on any platform right?
我不明白,为什么维基的例子:的http://维基.phonegap.com / W /页/ 42450600 / PhoneGap的% 20Ajax%20Sample
I don't understand why the example of the wiki: http://wiki.phonegap.com/w/page/42450600/PhoneGap% 20Ajax% 20Sample
正常工作在两个平台和矿山只能在iphone ...
works correctly in two platforms and mine only in iphone ...
推荐答案
检查跨域脚本问题。我几乎做同样的事情,但我的网址实际上位于同一个域。它好工作在Android和PC上,但iPhone拒绝工作。当我从'https://whatever.whatever.com/foo.asp'只是foo.asp改变 - 它的工作
Check for cross-domain scripting issues. I did almost the same thing, except my URL was actually located on the same domain. It worked fine on Android and on a PC, but the iphone refused to function. When I changed from 'https://whatever.whatever.com/foo.asp' to just foo.asp - it worked!
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;
}
}
另见:
这篇关于PhoneGap的XMLHtt prequest responseText的空与Android,但包含iphone数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!