Tutorial by Examples

In addition to .done, .fail and .always promise callbacks, which are triggered based on whether the request was successful or not, there is the option to trigger a function when a specific HTTP Status Code is returned from the server. This can be done using the statusCode parameter. $.ajax({ t...
Sometimes you may have a form and want to submit it using ajax. Suppose you have this simple form - <form id="ajax_form" action="form_action.php"> <label for="name">Name :</label> <input name="name" id="name" type="t...
jQuery makes handling jSON responses painless, but a bit more work is required when a given request wishes you to send data in JSON format: $.ajax("/json-consuming-route", { data: JSON.stringify({author: {name: "Bullwinkle J. Moose", ...
Ajax Get: Solution 1: $.get('url.html', function(data){ $('#update-box').html(data); }); Solution 2: $.ajax({ type: 'GET', url: 'url.php', }).done(function(data){ $('#update-box').html(data); }).fail(function(jqXHR, textStatus){ alert('Error occured: ' + te...
var xhr = $.ajax({ type: "POST", url: "some.php", data: "name=John&location=Boston", success: function(msg){ alert( "Data Saved: " + msg ); } }); //kill the request xhr.abort()
1. A Simple Complete Example We could use this sample code to upload the files selected by the user every time a new file selection is made. <input type="file" id="file-input" multiple>   var files; var fdata = new FormData(); $("#file-input").on("cha...

Page 1 of 1