使用 ajax 发布到 IP 在 Cordova 中不工作但在 phone 浏览器中工作正常

Posting to IP using ajax not working in Cordova but works fine with phone browser

我正在尝试 post 数据到我在 cordova 中的计算机 IP(如 url)。我可以从我的 phone 访问 IP,甚至可以使用 phone 浏览器测试 cordova 应用程序。 phone 浏览器完美运行。 当我 运行 我的 android phone(Android 9.0) 中的应用程序时,它陷入错误(无法在 'XMLHttpRequest' 上执行 'send' : 加载失败 'myIP'.

这是我的代码;

$.ajax({
            url: "http://xxx.xxx.xx.xxx:8000/arat", 
            data:{
                password:password,
                studentID:studentID
                },
            type:'post',
            //dataType: 'xml',
            async: false,
            contentType:"application/x-www-form-urlencoded",
            success: function(result){


                    alert("Data: "+result);

            },
            error: function(xhr, ajaxOptions, thrownError){

            alert("msg: "+thrownError+" , status: "+xhr.status);
            }
    });

如有任何帮助,我们将不胜感激。谢谢。

这是 android9 的 SSL 问题;必须按如下方式将 xml:android 添加到小部件;

<widget id="my.app.cordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:android="http://schemas.android.com/apk/res/android">

然后添加添加了以下平台;

<platform name="android">
  <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
      <application android:usesCleartextTraffic="true" />
  </edit-config>
</platform>

稍后谢谢我。