我构建了一个应用程序来将表单值插入远程位置的 MySQL 数据库。插入和检索在浏览器中运行良好。当我将应用程序转换为 APK 文件并从我的 Android 手机尝试时,它无法正常工作。
要插入的 Ajax:
$.ajax({
type: "POST",
url: "http://example.com/api/insert.php",
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function() {
$("#insert").val('Connecting...');
},
success: function(data) {
if (data == "success") {
alert("inserted");
$("#insert").val('submit');
} else if (data == "error") {
alert("error");
}
}
});
我做的配置:
在 html 文件中:
<meta http-equiv="Content-Security-Policy" content="*">
在 config.xml 中:
<access origin="*" />
<plugin name="cordova-plugin-whitelist" source="npm" spec="~1.2.1" />
并在远程 php 文件中:
header("Access-Control-Allow-Origin: *");
为什么我无法从手机连接?我在哪里做错了?