Taken from jQuery.ajax API web site:
$.ajax({
method: "POST",
url: "some.php",
data: {
name: "John",
location: "Boston"
},
success: function(msg) {
alert("Data Saved: " + msg);
},
error: function(e) {
alert("Error: " + e);
}
});
This chunk of code, due to jQuery, is easy to read and to understand what's going on.
$.ajax - this bit calls jQuery's ajax functionality.
method: "POST" - this line here declares that we're going to be using a POST method to communicate with the server. Read up on types of requests!
url - this variable declares where the request is going to be SENT to. You're sending a request TO somewhere. That's the idea.
data - pretty straight forward. This is the data you're sending with your request.
success - this function here you write to decide what to do with the data you get back msg! as the example suggests, it's currently just creating an alert with the msg that gets returned.
error - this function here you write to display error messages, or to provide actions to work when the ajax request went through errors.
an alternative to .done is
success: function(result) {
// do something
});