Prototype guide to the use of learning manuals ajax.js

Source: Internet
Author: User

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′,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.