Я использую Apache Cordova, чтобы превратить мобильную форму в мобильное приложение. Я пытаюсь отправить данные формы с помощью AJAX, и он отлично работает в Chrome как на моей мобильной форме, так и на рабочем столе. Тем не мение;когда я собираю пакет как приложение для Android, все идет гладко, за исключением вызова AJAX, и при нажатии кнопки появляется «Пожалуйста, подождите ...», но условие успеха никогда не достигается, только вмобильное приложение. (PS. Я жестко закодировал IP-адрес во время тестирования, он часто меняется).
AJAX:
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'">
$("#insert").click(function(){
//a bunch of variables are declared here I've chose to omit
if($.trim(dataString).length>0)
{
$.ajax({
type: "POST",
url:"http://10.0.0.107/insert.php",
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function(){ $("#insert").val('Please wait...');},
success: function(data){
$("#insert").val('Workorder Saved');
//document.getElementById('loading').style.display ='block';
//document.getElementById('secondform').style.display ='block'; // to display
$("#insert").attr(`disabled`, true);
var bar1 = new ldBar("#loading");
var bar2 = document.getElementById('loading').ldBar;
bar1.set(75);
}
});
} return false;
});
});
Кнопка:
<div class="col-xs-12 col-sm-12 col-lg-10">
<input type="button" class="btn btn-outline-info btn-lg btn-block" id="insert" value="Submit" style="padding: 15px;"/>
</div>
Cordova config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Citadel Plumbing</name>
<description>
Citadel Plumbing Form for Lift Station Maintenance and Inspections
</description>
<author email="itdept@stg4me.com" href="http://stg4me.com">
Southern Tier Graphics
</author>
<icon src="www/img/gauge.png" />
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<preference name="StatusBarBackgroundColor" value="#4282cc" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>