how to show progress on ajax call


$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();

// Upload progress
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
//Do something with upload progress
console.log(percentComplete);
}
}, false);

// Download progress
xhr.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
// Do something with download progress
console.log(percentComplete);
}
}, false);

return xhr;
},
type: 'POST',
url: "/",
data: {},
success: function(data){
// Do something success-ish
}
});

BY LOVE
You need to call the progress bar class, That's IT

beforeSend: function ()
{
$('.loaderimg').show();
},
complete: function ()
{
$(".loaderimg").hide();
}

www.codegrepper.com
www.stackoverflow.com

how to show a success message when ajax called successfully


BY LOVE,
1- "beforeSend" event used to execute something before ajax call
2- "complete" event used to execute something after the ajax called successfull.

$.ajax({
url: ' @Url.Action("AttendanceUpdateLate", "Attendance")',
data: { Emp: $("#txtEmpid").val(), Status: $("#ddlAttendance").val(), day: $("#ddlday").val(), Month: $("#Month").val() },
datatype: "json",
type: "POST",
contenttype: 'application/json; charset=utf-8',
async: true,
success: function (data) {
alert(data);
},
beforeSend: function () {
alert("Alert showing before AJAX call");

},
complete: function () {
alert("Alert showing after AJAX call successfully");
$("#txtEmpid").val('');
$("#ddlday").val('');
$("#ddlAttendance").val('');
},
error: function (xhr) {
alert('error occured');
}
});

www.codegrepper.com
www.stackoverflow.com

how to set json type jquery ajax


$.ajax({
type: "POST",
url: siteRoot + "api/SpaceGame/AddPlayer",
async: false,
data: JSON.stringify({ Name: playersShip.name, Credits: playersShip.credits }),
contentType: "application/json",
complete: function (data) {
console.log(data);
wait = false;
}
});

$.ajax({
type: "POST",
contentType: "application/json",
url: 'http://localhost:16329/Hello',
data: { name: 'norm' },
dataType: "json"
});

www.codegrepper.com
www.stackoverflow.com

how to send authorization in header of HTTP GET using ajax


var username="username_here";
var password="password_here";
$.ajax({
type: "GET",
url: "myapi.php",
dataType: 'json',
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
},
success: function (result){
console.log(result)
}
});

AJAX Authorization

www.codegrepper.com
www.stackoverflow.com