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