Home > Article > Web Front-end > Example of universal ajax() function for ajax application in jquery
jquery series tutorial 6-AJAX full solution
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全局函数});
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请求成功
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!