Home > Web Front-end > JS Tutorial > Instructions for using the AJAX framework of javascript_javascript skills

Instructions for using the AJAX framework of javascript_javascript skills

WBOY
Release: 2016-05-16 18:28:46
Original
1035 people have browsed it
The implementation of ajax coding is a milestone in the team's framework construction, which enables the framework to have an application-debugging version. The following are the main points that come to mind when coding the ajax framework:
  • Framework Compatibility
  • The method is comprehensive but simple and quick
  • Good scalability
Framework compatibility: The compatibility of the ajax framework is mainly reflected in the generation of XMLHttpRquest objects. There are generally three methods according to different types of browsers or different libraries
  • new XMLHttpRequest();
  • new ActiveXObject("Microsoft.XMLHTTP");
  • new ActiveXObject("Msxml2.XMLHTTP");
The method is simple, fast and scalable
  • Framework writing such as ajax.get(), ajax.json(), ajax.post, etc. is a relatively comprehensive method similar to jquery, which is fast and convenient
  • The framework uses a core method as the interface, and various methods make asynchronous requests through the unified interface. If you need extension methods later, you only need to organize your own data format, and then call the core method.
Method
  • ajax.get(url,success,error)
    参数: url 请求的url地址 必选
    参数: success 请求成功的回调函数 可选
    参数: error 请求失败的回调函数 可选
  • ajax.json(url,success,error)//Use the official json parsing method to parse, which is safer
    参数: url 请求的url地址 必选
    参数: success 请求成功的回调函数 可选
    参数: error 请求失败的回调函数 可选
  • ajax.xml(url,success,error)//Not supported yet
    参数: url 请求的url地址 必选
    参数: success 请求成功的回调函数 可选
    参数: error 请求失败的回调函数 可选
  • ajax.post(url,params,success,error)
    参数: url 请求的url地址 必选
    参数: params 需要post的参数 可选(默认null)
    参数: success 请求成功的回调函数 可选
    参数: error 请求失败的回调函数 可选
  • ajax.request( { url:url, params:params, type:type, format:format, success:success, error:error } )
    参数: url 请求的url地址 必选
    参数: params 需要post的参数 可选
    参数: success 请求成功的回调函数 可选
    参数: error 请求失败的回调函数 可选
    参数: type 请求类型(POST/GET) 可选(默认GET)
    参数: format 返回数据类型(json/xml/text) 可选(默认text)
Example
Introduction
Copy code The code is as follows:

Request
Copy code The code is as follows:



Download ajax_min.js
From: cnblogs Only C—Sky
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template