AJAX
AJAXRead data from a web server - after the page has loadedUpdate a web page without reloading the pageSend data to a web server - in the background
XMLHttpRequest Object
$.ajax({
url: "http://localhost:8080/login",
type: 'GET',
// Fetch the stored token from localStorage and set in the header
headers: {"Authorization": localStorage.getItem('token')}
});
$.ajax({
url: "http://localhost:8080/login",
type: "POST",
headers: { Authorization: $`Bearer ${localStorage.getItem("token")}` },
data: formData,
error: function(err) {
switch (err.status) {
case "400":
// bad request
break;
case "401":
// unauthorized
break;
case "403":
// forbidden
break;
default:
//Something bad happened
break;
}
},
success: function(data) {
console.log("Success!");
}
});XMLHttpRequest Object Methods
XMLHttpRequest Object Properties
Send a Request To a Server
Last updated