2017-07-18 16 views
1

我有一个在后端使用PHP的Adobe PhoneGap应用程序。网络更改后(如WiFi - > 4G),每当有XMLHttpRequest(或与服务器通信)时,应用程序都会崩溃。如果我让应用程序“冻结”3分钟,应用程序将继续正常工作。我正在测试Android手机,并带有“内置”.apk文件。PhoneGap应用程序在使用XMLHttpRequest进行网络更改后冻结/锁定

我试过/正在做什么。这是在我的配置文件

<plugin name="cordova-plugin-whitelist" source="npm" spec="https://github.com/apache/cordova-plugin-whitelist" /> 
    <allow-intent href="http://*/*" /> 
    <allow-intent href="*://*api.parse.com/*"/> 

And here is what my code looks like that is communication with PHP 

    function getProducts() { 
     var url = 'http://www.*.com/*/*/getProducts.php'; 
     var params = "ID=1" + 

     var xhr = new XMLHttpRequest(); 

     xhr.open('GET', url + "?" + params, false); 
     xhr.addEventListener("readystatechange", processRequest, false); 

     function processRequest(e) { 
     if (xhr.readyState == 4 && xhr.status == 200) { 
     document.getElementById("results").innerHTML = xhr.response; 
     } 
    } 

    xhr.send(params); 
    } 

有没有其他人跑过这个问题呢?

这里是所有插件我使用

<preference name="android-minSdkVersion" value="14" /> 
    <plugin name="cordova-plugin-console" source="npm" spec="https://github.com/apache/cordova-plugin-console" /> 
    <plugin name="cordova-plugin-device" source="npm" spec="https://github.com/apache/cordova-plugin-device"/> 
    <plugin name="cordova-plugin-device-orientation" source="npm" spec="https://github.com/apache/cordova-plugin-device-orientation" /> 
    <plugin name="cordova-plugin-dialogs" source="npm" spec="https://github.com/apache/cordova-plugin-dialogs" /> 
    <plugin name="cordova-plugin-geolocation" source="npm" spec="https://github.com/apache/cordova-plugin-geolocation" /> 
    <plugin name="cordova-plugin-globalization" source="npm" spec="https://github.com/apache/cordova-plugin-globalization" /> 
    <plugin name="cordova-plugin-inappbrowser" source="npm" spec="https://github.com/apache/cordova-plugin-inappbrowser" /> 
    <plugin name="cordova-plugin-splashscreen" source="npm" spec="https://github.com/apache/cordova-plugin-splashscreen" /> 
    <plugin name="cordova-plugin-network-information" source="npm" spec="https://github.com/apache/cordova-plugin-network-information" /> 
    <plugin name="cordova-plugin-statusbar" source="npm" spec="https://github.com/apache/cordova-plugin-statusbar" /> 
    <plugin name="cordova-plugin-whitelist" source="npm" spec="https://github.com/apache/cordova-plugin-whitelist" /> 

编辑:看来,如果我的应用程序不进入功能processRequest

EDIT2:看来,这个错误仅是机器人。我在Apple iPhone 6上测试过,并没有问题。我也将我的getProducts函数更改为onreadystatechange类型。它现在不锁定应用程序,但它不加载PHP结果,直到我打开/重新打开该页面6次。 XMLHttpRequest.readyState属性返回1,但不会返回2,3或4(直到6次后)。

回答

0

尝试重新安装network-information插件。

cordova plugin rm org.apache.cordova.network-information 
cordova plugin add https://github.com/apache/cordova-plugin-network-information 

可能有帮助。

p.s.如果navigator.connection.type已更改,请尝试重新启动所有请求。
不要忘了,科尔多瓦2.3.0之后navigator.connection.type更改为navigator.connection

+0

感谢您的评论。我重新安装了网络信息插件,但没有任何帮助。我的网页工作,直到有php/xmlhttp交互。 – Brandon

0

我在另外两个wifi网络上测试了这个,并且无法复制这个问题。也许防火墙问题?或者PHP文件/服务器在该网络上。