JavaScript Ajax Framework Usage Instructions _javascript Tips

Source: Internet
Author: User

Ajax code Landing is a milestone in the construction of a team framework, which enables the framework to have a version that can be applied for debugging. This is mainly thought of in the AJAX Framework code:

  • Framework Compatibility
  • Methods are comprehensive and simple and quick
  • Good scalability

Framework compatibility: The compatibility of Ajax frameworks is mainly manifested in Xmlhttprquest object generation. There are three ways to do this depending on the type of browser or different library

  • New XMLHttpRequest ();
  • New ActiveXObject ("Microsoft.XMLHTTP");
  • New ActiveXObject ("Msxml2.xmlhttp");

The method is simple, fast and scalable.

  • Frameworks such as Ajax.get (), Ajax.json (), Ajax.post, and so a more comprehensive approach like jquery, fast and convenient
  • The framework uses a core method for the interface, various methods are asynchronous requests through the unified interface, the subsequent need to extend the method only to organize their own data format, and then call the core method.

Method

  • Ajax.get (Url,success,error)
    Parameters: Url URL address of the request Must select
    Parameters: Success Request a successful callback function Optional
    Parameters: Error callback function with request failed Optional
  • Ajax.json (Url,success,error)//using the official JSON parsing method, more secure
    Parameters: Url URL address of the request Must select
    Parameters: Success Request a successful callback function Optional
    Parameters: Error callback function with request failed Optional
  • ajax.xml (Url,success,error)/temporarily does not support
    parameters: URL address of the request Required
    parameter: success Request successful callback function optional
    parameter: error request failed callback function optional
  • ajax.post (url,params,success,error)
    parameters: url required
    parameter : params requires a post parameter optional (default null)
    parameter: success Request a successful callback function optional
    parameter: E Rror request failed callback function optional
  • Ajax.request ({url:url, params:params, Type:type, Format:format, success:success, error:error})
    Parameters: Url URL address of the request Must select
    Parameters: Params Parameters that require post Optional
    Parameters: Success Request a successful callback function Optional
    Parameters: Error callback function with request failed Optional
    Parameters: Type Request Type (Post/get) Optional (default get)
    Parameters: Format Return data type (Json/xml/text) Optional (default text)
Example
Introduced
Copy Code code as follows:
<script type= "Text/javascript" src= "Ajax_min.js" ></script>

Request
Copy Code code as follows:

<script type= "Text/javascript" >
Defining callback Functions
var callBack = function (text)
{
alert (text);
}
Send Request
Ajax.get ("test.php", callBack);
</script>

Download Ajax_min.js
From: Cnblogs 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.