Ajax is a set of web development techniques
that uses various web technologies on the
client-side to create asynchronous web
applications.
With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behaviour of the existing page.
AJAX - Asynchronous JavaScript And XML
var xhr = new XMLHttpRequest;
var url = "/?lorem=ipsum";
//GET request
xhr.open('GET', url); //Open the request with the specified url.
xhr.onreadystatechange = () => {
//Checking if the request has finished and if it was successfull
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText); //Printing out the response.
//You can also use xhr.responseXML
}
}
xhr.send(); //This sends the request to the server with the specified params.
$.ajax({
method :'GET',
url: baseUrl+'ajaxcontroller/LoadData_To_View',
success:function(data){
$('#item').html(data);
alert(data);
},
complete: function(){
$('#loadingImage2').hide();
},
error:function (xhr, ajaxOptions, thrownError){alert(thrownError);}
});
var value = $("#quicksearchtext").val();
var model =
{
industryCode : value
}
$.ajax({
url: "/Setting/GetSubIndustryList",
type: "POST",
contentType: "application/json;charset=utf-8",
dataType: "json",
async: false,
data: JSON.stringify(model),
success: function (res) {
console.log('doGetBeamSubIndustry success');
$("#txtBusinessSubIndustry").find('option').remove();
$.each(res.message, function (index, value) {
$("#txtBusinessSubIndustry").append("<option value=" + value.code + ">" + value.names.en + "</option>");
});
},
error: function (jqXHR, exception) {
console.log('doGetBeamSubIndustry error');
console.log(jqXHR.responseText);
}
});
$.ajax({
url: 'some_unknown_page.html',
success: function (response) {
$('#post').html(response.responseText);
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.
Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.
' + jqXHR.responseText;
}
$('#post').html(msg);
},
});