【发布时间】:2018-03-12 03:00:18
【问题描述】:
Phonegap ajax 方法 GET 运行良好,但 POST 给出错误。我已尝试使用cordova-plugin-whitelist,但仍然没有找到错误 404。
这是我的 ajax 代码
function GetSlider(){
serverRoot = "/js/ajax.php";
$.ajax({
type: "post",
url: serverRoot,
data: "act=GetSlider",
dataType: "JSON",
beforeSend: function(){
$("#loading").show();
},
success: function(){
$("#loading").hide();
}
});
}
config.xml
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<plugin name="cordova-plugin-whitelist" spec="~1.2.2" />
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="data:*" />
<allow-navigation href="dubailibrary.com*" />
<access origin="*" />
回复:Cannot POST /js/ajax.php
【问题讨论】:
-
你正在调用一个本地的php文件,这是行不通的。您必须使用远程服务器,例如www.example.com/js/ajax.php
-
感谢 Joerg 的工作。但是有什么解决方案可以在本地运行吗?
-
你不能在 phonegap 应用上运行 php,你需要一个服务器。
标签: jquery ajax cordova http-status-code-404 phonegap-plugins