I'm trying to post data from a form to a codeigniter controller in a web server I deployed on a host online. It works when I use it on my laptop, but after I build it in build.phonegap.com
and install it in my phone, it doesn't work. Here's the code in the index.html file:
Javascript:
function sendMessage(){
//get values from the form
var msgFrom = $('#msgFrom').val();
var msgTo = $('#msgTo').val();
var msg = $('#msg').val();
//works up to here only after building on build.phonegap.com
$.ajax({
traditional: true,
type: 'POST',
dataType:'json',
url: '<...>/welcome/savePostData',
data: 'numberTo='+msgTo+'&numberFrom='+msgFrom+'&message='+msg,
success: function(resp) {
Materialize.toast("Posted", 5000);
}
});
}
Here are the resources in my HTML code:
<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.4.5.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"></script>
Other details:
cordova create <appname>
android kitkat (lol
) freewebhostingarea.com
it sounds like the mobile ajax isn't enabled. have you set $.support.cors to true?
source: http://demos.jquerymobile.com/1.0/docs/pages/phonegap.html
In order to use cross-domain AJAX requests you need to add the following code at the end of your config.xml file. This is what worked for me:
<access origin="*"/>
<gap:plugin name="cordova-plugin-whitelist" source="npm"/>
<access url="*" subdomains="true"/>
<allow-intent href="http://*/*"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.