Home > Web Front-end > JS Tutorial > What support does Jquery have for ajax?

What support does Jquery have for ajax?

一个新手
Release: 2017-09-21 10:05:26
Original
1198 people have browsed it

AJAX = (Asynchronous JavaScript and XML)Asynchronous JavaScript and XML.
Function: By exchanging a small amount of data with the server in the background, AJAX can enable asynchronous updates of web pages. Parts of a web page can be updated without reloading the entire page.

Jquery’s support for AJAX

//jquery调用ajax相对于js的优势:
    1.代码简洁。
    2.多浏览器支持。
    3.逻辑处理更清晰。
    4.有单独的对错误处理函数以及获取正确结果的处理函数。
$.ajax({
    url:'',
    async:boolean,
    beforeSend:function(XHR){},
    cache:boolean,
    contentType:'',
    type:'',
    data:'',
    dataType:'',
    success:function(data){},
    error:function(data){},

});
//参数解析
url:String类型,默认当前页地址。表示发送请求的地址。
async:Boolean类型,默认true,表示均为异步请求。如果需要发送同步请求,设置此参数为false,通常当第二个ajax函数需要第一个的ajax返回结果时,需要将第一个设置为false。
beforeSend:function类型,发送请求前可以修改XMLHttpRequest对象的函数,如添加自定义HTTP头。这是一个ajax事件。如果返回false可以取消本次ajax请求。
cache:Boolean类型,默认true,dataType为script和jsonp时默认为false。设置为false时将不缓存此页面。
contentType:发送信息至服务器时内容编码类型。默认值适合大多数情况。
type:String类型,默认GET,可以是POST,PUT,DELETE。
data:String类型,发送到服务器的数据。GET请求中将附加在URL后。必须为key/value的形式。
dataType:String类型,预期服务器返回的数据类型。不指定则自动智能匹配。可以是:xml,html,script,json,jsonp,text。
success:function类型,请求成功后的回调函数。由data参数处理后台数据。
error:function类型,请求失败的回调函数。有三个参数,XMLHttpRequest对象,错误信息,捕获的异常对象。如果发生了错误,错误信息除了得到null外,还可能是"timeout","error","notmodified"和"parsererror"。
Copy after login

Commonly used methods in development

$.ajax({
    url:"",
    type:"",
    data:"",
    dataType:"",
    success:function(data){},
    error:function(xhr){}
});
$.get(url,data,function,dataType);
Copy after login

AJAX = (Asynchronous JavaScript and XML)Asynchronous JavaScript and XML.

Function: By exchanging a small amount of data with the server in the background, AJAX can enable asynchronous updates of web pages. Parts of a web page can be updated without reloading the entire page.

The above is the detailed content of What support does Jquery have for ajax?. For more information, please follow other related articles on the PHP Chinese website!

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