Javascript Ajax framework instructions

Source: Internet
Author: User

The implementation of Ajax encoding is a milestone in the construction of the Team framework, so that the framework has a version that can be used for application debugging. In the Ajax framework encoding, we mainly think of the following points:
    • Framework compatibility
    • Comprehensive and easy to use
    • Good scalability
Framework compatibility: the compatibility of the Ajax framework is mainly manifested in xmlhttprquest object generation. There are generally three methods based on different types of browsers or libraries
    • New XMLHttpRequest ();
    • New activexobject ("Microsoft. XMLHTTP ");
    • New activexobject ("msxml2.xmlhttp ");
The method is simple, fast, and scalable.
    • This is a comprehensive method similar to jquery, such as Ajax. Get (), Ajax. JSON (), and Ajax. Post.
    • The framework uses a core method as an interface, and various methods use a unified interface for asynchronous requests. To expand the method, you only need to organize your own data format and then call the core method.
Method
  • Ajax. Get (URL, success, error)

    Parameters: URL Requested URL Required
    Parameters: Success Callback Function for successful request Optional
    Parameters: Error Callback Function for request failure Optional
  • Ajax. JSON (URL, success, error) // use the official JSON Parsing Method for better security
    Parameters: URL Requested URL Required
    Parameters: Success Callback Function for successful request Optional
    Parameters: Error Callback Function for request failure Optional
  • Ajax. XML (URL, success, error) // currently not supported
    Parameters: URL Requested URL Required
    Parameters: Success Callback Function for successful request Optional
    Parameters: Error Callback Function for request failure Optional
  • Ajax. Post (URL, Params, success, error)
    Parameters: URL Requested URL Required
    Parameters: Params Post Parameters Optional (null by default)
    Parameters: Success Callback Function for successful request Optional
    Parameters: Error Callback Function for request failure Optional
  • Ajax. request ({URL: URL, Params: Params, type: type, format: format, success: Success, error: Error})
    parameter: URL requested URL required
    parameter: Params post parameters optional
    parameter: success callback function for successful requests optional
    parameter: error callback function for request failure optional
    parameter: type request type (post/get) optional (default get)
    parameter: Format return data type (JSON/XML/Text) optional (default text)

Example
IntroductionCopyCodeThe Code is as follows: <SCRIPT type = "text/JavaScript" src = "ajax_min.js"> </SCRIPT>

RequestCopy codeThe Code is as follows: <SCRIPT type = "text/JavaScript">
// Define the callback function
VaR callback = function (text)
{
Alert (text );
}
// Send the request
Ajax. Get ("test. php", callback );
</SCRIPT>

Download ajax_min.js
From: cnblogs only C-sky

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.