Home > Web Front-end > JS Tutorial > Example of universal ajax() function for ajax application in jquery

Example of universal ajax() function for ajax application in jquery

黄舟
Release: 2017-09-07 14:07:45
Original
1496 people have browsed it

jquery series tutorial 6-AJAX full solution

ajax application in jquery-general ajax function

jquery provides ajax() that is more versatile than get and post

The code is as follows:

$.ajax(options)
$.ajax({
    type:"POST",                                               //方式
    url:"test.jsp",                                            //地址
    dataType:"JSON",                                           //数据类型  xml(xml文档),html(html代码),script(js代码),json(json数据),jsonp(jsonp格式数据),text(纯文本)
    beforeSend:function(XMLHttpRequest){                        //发送前函数, 这里可以修改XMLHttpRequest,例如添加HTTP头
    },
    complete:function(XMLHttpRequest,textStatus){               //请求完成函数,请求成功或失败均调用此函数
    },
    sucess:function(data,textStatus){                           //请求成功,成功返回,    //data有可能是xmlDoc,jsonObj,html,text等等
    },
    error:function(XMLHttpRequest,textStatus,errorThrown){      //请求失败函数
    },
    global:true                                                 //是否触发全局ajax事件,默认为true。全局函数开启,任何jquery类能调用后面的ajax全局函数});
Copy after login

Global ajax function

Any jquery object can call the global ajax function
The code is as follows:

$("#loading").ajaxStart(function(){});   //ajaxStart请求开,ajaxStop请求结束   ajaxComplete请求完成    ajaxError请求错误    ajaxSend发送请求前    ajaxSucess请求成功开,ajaxStop请求结束   ajaxComplete请求完成    ajaxError请求错误    ajaxSend发送请求前    ajaxSucess请求成功
Copy after login

The above is the detailed content of Example of universal ajax() function for ajax application in jquery. 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