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