As you tagged jquery, Here is a way of making an AJAX call with jquery:
$.ajax({
url: "next.htm",
type: "POST", // This could be POST, GET, PATCH, HEAD, etc..
dataType: 'json',
data: JSON.stringify({"value1": "test"}),
complete: function(data) {
alert(data);
}
});
The complete function, as http://api.jquery.com/jquery.ajax/ says:
A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string categorizing the status of the request ("success", "notmodified", "error", "timeout", "abort", or "parsererror"). As of jQuery 1.5, the complete setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.
This function is being executed whether the HTTP request is successful or not, so maybe you could handle the different HTTP status in the response, using:
if (data.status == 200) console.log('Request succeed');
$.post("next.htm", {"data" : data}, function(response){ /*do something with reponse eg: alert(response);*/ });