how to make an ajax call in javascript code example
Example 1: ajax exmaple\
$.ajax({
url:'your url',
type: 'POST',
data: { myData: 'This is my data.' },
success: function (data, status, xhr) {
$('p').append('status: ' + status + ', data: ' + data);
},
error: function (jqXhr, textStatus, errorMessage) {
$('p').append('Error' + errorMessage);
}
});
Example 2: ajax syntax in javascript
var id = empid;
$.ajax({
type: "POST",
url: "../Webservices/EmployeeService.asmx/GetEmployeeOrders",
data: "{empid: " + empid + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result){
alert(result.d);
console.log(result);
}
});
Example 3: js functional ajax requests
function checkUserIdExists(userid, callback) {
return $.ajax({
url: 'theurl',
type: 'GET',
cache: false,
data: {
userid: userid
}
})
.done(callback)
.fail(function(jqXHR, textStatus, errorThrown) {
});
}
checkUserIdExists(2, function(data) {
console.log(data);
});