http://www.runoob.com/jquery/jquery-ref-ajax.html
http://jun1986.iteye.com/blog/1399242
下面是jQuery官方给出的完整的Ajax事件列表:
- ajaxStart (Global Event)
This event is broadcast if an Ajax request is started and no other Ajax requests are currently running.
- beforeSend (Local Event)
This event, which is triggered before an Ajax request is started, allows you to modify the XMLHttpRequest object (setting additional headers, if need be.)
- ajaxSend (Global Event)
This global event is also triggered before the request is run.
- success (Local Event)
This event is only called if the request was successful (no errors from the server, no errors with the data).
- ajaxSuccess (Global Event)
This event is also only called if the request was successful.
- error (Local Event)
This event is only called if an error occurred with the request (you can never have both an error and a success callback with a request).
- ajaxError (Global Event)
This global event behaves the same as the local error event.
- complete (Local Event)
This event is called regardless of if the request was successful, or not. You will always receive a complete callback, even for synchronous requests.
- ajaxComplete (Global Event)
This event behaves the same as the complete event and will be triggered every time an Ajax request finishes.
- ajaxStop (Global Event)
This global event is triggered if there are no more Ajax requests being processed.
$.post、$.get是一些简单的方法,如果要处理复杂的逻辑,还是需要用到jQuery.ajax()
一、$.ajax的一般格式
$.ajax({
type: ‘POST‘,
url: url ,
data: data ,
success: success ,
dataType: dataType
});
二、$.ajax的参数描述
参数 描述
url |
必需。规定把请求发送到哪个 URL。 |
data |
可选。映射或字符串值。规定连同请求发送到服务器的数据。 |
success(data, textStatus, jqXHR) |
可选。请求成功时执行的回调函数。 |
dataType |
可选。规定预期的服务器响应的数据类型。
默认执行智能判断(xml、json、script 或 html)。
|
三、$.ajax需要注意的一些地方:
1.data主要方式有三种,html拼接的,json数组,form表单经serialize()序列化的;通过dataType指定,不指定智能判断。
2.$.ajax只提交form以文本方式,如果异步提交包含<file>上传是传过不过去,需要使用jquery.form.js的$.ajaxSubmit
jQuery ajax
原文:http://www.cnblogs.com/carlo/p/4632471.html