gpt4 book ai didi

javascript - phonegap XMLHttpRequest 响应文本在 galaxy s4 中返回空但不是 galaxy note

转载 作者:行者123 更新时间:2023-11-29 17:52:48 28 4
gpt4 key购买 nike

我在连接到我的服务器以检查我的电话应用程序的凭据时遇到问题,我正在使用 phonegap 来开发它。

我已经检查过这些问题,但它们没有给我我正在寻找的东西

HTTP Requests in Phonegap

HTTP methods in PhoneGap

我已经阅读了有关该主题的内容,并使用 get 请求制作了多个站点,因此我对此事有很好的理解,我只是不确定发生了什么。

http://simonmacdonald.blogspot.com/2011/12/on-third-day-of-phonegapping-getting.html

这是我的代码:

login.onclick = function() {
var req = new XMLHttpRequest();
req.open('GET', 'myServer'+username.value+".json", true);
req.send();

req.onreadystatechange = function() {
if (req.readyState == 4) {
if( (req.status == 200) || (req.status == 0) ) {
var json = JSON.parse(req.responseText);
if(json.length > 0) {
if((json[0]["username"] == username.value) && (json[0]["phoneCred"] == password.value)){
localStorage.setItem("loggedIn",username.value);
location.reload();
}
else {
alert("Incorrect password");
}
}
else {
alert("Incorrect username");
}
}
else {
alert("Error talking to server");
}
}
}
};

我将 req.status == 0 添加到 if 中,现在我的按钮完全没有响应,我至少收到了我没有与服务器通话的警报。如果有人有任何见解,将不胜感激!

好吧,我的代码中有几个错误,我修复了这些错误,所以这是我更新的代码:

login.onclick = function() {
var req = new XMLHttpRequest();
req.open('GET', 'myServer'+username.value+'.json', true);
req.send();

alert('myServer'+username.value+'.json');
req.onreadystatechange = function() {
if (req.readyState == 4) {
if( (req.status == 200) || (req.status == 0) ) {

//alert(req.responseText.length);
alert(req.responseText);
if(req.responseText.length > 0) {
var json = JSON.parse(req.responseText);
if( (json[0].username == username.value) && (json[0].phoneCred == password.value) ){
localStorage.setItem("loggedIn",username.value);
location.reload();
}
else {
alert("Incorrect password");
}
}
else {
alert("Incorrect username");
}
}
else {
alert("Error talking to server");
}
}
}
};

我有两部手机我一直在测试,它在我的 galaxy note 上工作,但在我的 galaxy s4 上不工作,如果这可能是对任何事情的暗示的话。

我还将我的 xml 文件中的访问标记更改为

<access origin=".*" />

在我做了一些阅读之后

Phonegap + Android status=0 returned from webservice

phonegap XMLHttpRequest responseText empty with android but contain data in iphone

Empty responseText from XMLHttpRequest

但我的 galaxy s4 似乎仍然没有从服务器接收到任何数据。它可能是同源策略或某些我不确定的互联网访问设置。如果有人有任何建议,我将不胜感激。

最佳答案

修复它。我需要添加

<access origin="http://google.com" />

到 config.xml 文件,其中 google.com 是我自己的服务器。 Phonegap 现在有一些不错的文档,您可以在此处查看

http://docs.phonegap.com/en/3.3.0/guide_appdev_whitelist_index.md.html#Whitelist%20Guide

关于javascript - phonegap XMLHttpRequest 响应文本在 galaxy s4 中返回空但不是 galaxy note,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21791656/

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