AJAX known as Asynchronous JavaScript and XML. AJAX is another strategy for making better, faster, and more intelligent web applications with the assistance of XML, HTML, CSS and Java Script.
Prototype framework empowers you to manage Ajax brings in a simple and easy way which is additionally safe. Prototype additionally deals with JavaScript code came back from a server and gives assistant classes for polling. Ajax usefulness is contained in the global Ajax object.
Ajax Request
Ajax request is the general purpose ajax requester which handles the life cycle of the request and which manage the boilerplate and for custom needs which plug in the callback functions the syntax for the Ajax request as shown below.
[code]
new Ajax.Request(url[, options])
[/code]
With the above syntax which Starts and procedures an AJAX request which handles the life-cycle of the request, handles the boilerplate, and which gives you a chance to connect to callback capacities for custom needs.
In the discretionary options hash, user typically give a
onComplete as well as
onSuccess callback, unless user are in the edge situation where he getting a JavaScript-typed response, which will consequently be evaluated. For a full list of basic alternatives and callbacks, see Ajax Options.
The main legitimate approach to make a requester is through the new operator. When the object is made, it starts the request, then which continues processing it for the duration of its life-cyle.
Ajax Response
Ajax requests are asynchronous, which implies user should have callbacks that will handle the information from a response. Callback methods are passed in the alternatives hash when making a request The code below demonstrates to making the Ajax request.
[code]
new Ajax.Request('/some_url', {
method:'get',
onSuccess: function(transport) {
var response = transport.responseText || "no response text";
alert("Success! \n\n" + response);
},
onFailure: function() { alert('Something went wrong...') }
});
[/code]
Following are the two call backs in the hash are shown below.
Based on the response status hash call backs can be called accordingly. The main parameter go to both is the native xmlHttpRequest object from which user can utilize its responseText and responseXML properties, separately.