GET and Post data from server using Cordova JQuery $.ajax() .

Get and post request are basically used to fetch response from server so here are the following steps to achieve this,

1.we need to add following two header files into server side Php file.

header(‘Access-Control-Allow-Origin:*’);
header(‘Access-Control-Allow-Methods: GET,POST,PATCH,PUT,DELETE,OPTIONS’);

2.we need to call jquery$.ajax() and passes all the essential detials

example of sending POST request type are as follow.

functionregisterEvent(){
alert(“reached here 1”);
varemail = $(“#username1”).val();
varpassword = $(“#password1”).val();
varfirst_name = $(“#f_name”).val();
varlast_name = $(“#l_name”).val();
alert(“reached here 2”);
varformData = “first_name=”+first_name+”&last_name=”+last_name+”&email=”+ email+”&password=”+password;
$.ajax({
url: “http://www.example.com”,
type: “POST”,
data:formData,
cache:false,
success: function(response) {
alert(“Success “+response);
},
error: function(response) {
alert(“Err “+response);
}
});
// window.location.href = “homepage.html”;
}