Getting Start with Ajax
https://dzone.com/refcardz/getting-started-ajax
http://www.c-sharpcorner.com/blogs/calling-a-webmethod-using-jquery-ajax1
Immediately Invoked Function Expression
<script>
// IIFE - Immediately Invoked Function Expression
(function (main) {
// The global jQuery object is passed as a parameter
main(window.jQuery, window, document);
}(function ($, window, document) {
// The $ is now locally scoped
// Listen for the jQuery ready event on the document
$(function () {
// The DOM is ready!
// TODO: Put your code here
});
// The rest of the code goes here!
}));
</script>
AJAX
$.ajax({
type: "POST",
url: '/api/SaveData',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
Email: inputEmail,
Password: inputPassword,
RememberMe: rememberme
}),
success: function (data) {
debugger;
console.log(data);
},
error: function (error) {
debugger;
console.log(error);
}
});
$.ajax({
type: "POST",
url: url,
contentType: 'application/json; charset=utf-8',
data: postData,
dataType: "json",
success: function (result) {
}
});
$.ajax({
//Other code
success: function(msg) {
// Update the UI here to reflect that the request was successful.
doSomethingClever();
},
error: function(msg) {
// Update the UI here to reflect that the request was unsuccessful
doSomethingMoreClever();
},
complete: function(msg) {
// Update the UI here to reflect completion
doSomethingEvenMoreClever();
}
});
$.ajax({
// Switch off caching
cache: false,
//Set the type of request
type: "GET",
// Set the timeout
timeout: 5000,
// Specify the proper handler
url: "handler.php",
success: function(msg) {
// Update the UI here to reflect that the request was successful.
doSomethingClever();
},
error: function(msg) {
// Update the UI here to reflect that the request was unsuccessful
doSomethingMoreClever();
}
});
JQUERY BEST PRACTICES
http://gregfranko.com/jquery-best-practices/