你好,我想用我的网站代码构建一个混合应用程序,但问题是我读到Phonegap不支持我的ajax请求。你知道其他选择吗?你能和我分享吗?
我的Ajax请求:
$.ajax({
type: "POST",
url: "http://quantivorquali.de/amk.Neusocken.php",
data:{nam_ersteller:nam_ersteller, punkte:punkte, text:text, benachrichtigung:benachrichtigung, status:status},
success: function(data){
window.location = "http://quantivorquali.de/amk.html";
}
})
Phonegap支持ajax请求,但您需要执行以下操作。
确保您的php文件在每个php文件的顶部都有以下行-这允许应用程序访问php文件:
header('Access-Control-Allow-Origin: *');
脚本中的成功结果会将应用程序重定向到应用程序外部的外部网站,除非您使用Phonegap的相关插件。
您可能需要添加:
cordova-plugin-whitelist
cordova-plugin-inappbrowser
到您的config.xml文件以及
<access origin="*" />
<allow-navigation href="*" />
<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="https://*.someURL.com/*" />
以下内容有效吗?
hello.hp:
<?php
header('Access-Control-Allow-Origin: *');
echo 'Hello World';
?>
Ajax:
$.ajax({
type: "POST",
url: "https://www.exampleURL.com/hello.php",
dataType:"html",
data:"some=string",
success: function(data){
alert(data)
}
})