Like many developers who used this class library before, I had to dive into reading Prototype.js's source code and experimenting with its functionality. Prototype in the Ajax.js provides a very useful AJAX framework, the general application of the simple call to the following code can be
new Ajax.Request(
url, {method: “get”,
onSuccess: showFilter,
onFailure: function(request){alert(”Server error!”)},
onException: showError}
);
The following objects and methods are provided in this framework:
Ajax object: There is only one Gettransport method that returns a XMLHttpRequest object, and another Activerequestcount property that reflects the number of Ajax currently being processed
Ajax.responders object: Inherits from Enumerable, manages the global Ajax request, has the following method:
Register (Responder): Registers an object that manages AJAX requests
Unregister (Responder): Undo an object that manages an AJAX request
Dispatch (callback, request, Transport, JSON): Methods to trigger registered processing objects
This object is rarely used, and the system already registers a processing object with the following code
Ajax.Responders.register({
onCreate: function() {
Ajax.activeRequestCount++;
},
onComplete: function() {
Ajax.activeRequestCount–;
}
});
Ajax.base class:
Ajax base class, only one method SetOptions (options), the default request parameter is as follows, you can specify when you create a new ajax.request:
method:'post’,
asynchronous: true,
contentType:'application/x-www-form-urlencoded’,
encoding:'UTF-8′,