问题
i desing my page with jquerymobile and i do native app for android with phonegap. it is working but in my page i have form and i have to get some value and after that i will send value/data with webservice. How can i do that ? i research about that but i found some documents these are so complex and not working. so do you have some exapmle/sample ? Thanks
回答1:
$.ajax({
url: PublishUrl,
type: 'POST',
data: JSON.stringify(postData),
contentType: "application/json;charset=utf-8",
success: function (result) {
},
error: function (x, y, z) {
alert(x.responseText +" "+ x.status);
}
});
postData = data in json format PublishUrl = url where you need to call the service
This same can be used to post and call too, you can change type to "GET" and loop through in your success block
回答2:
Submit form data on click button add following code
var ajax_call = web_service_URL;
var str = $('#frm_id').serialize();;
$.ajax({
type: "POST",
url: ajax_call,
data: str,
cache:false,
dataType: "json",
success: function(response){
}
}).done(function() {
})
return false;
来源:https://stackoverflow.com/questions/20329295/call-and-post-value-webservice-with-jquery-mobile-or-phonegap