欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ajax事件与参数详解

程序员文章站 2023-03-02 10:32:36
ajax事件: ajaxStart (Global Event) This event is broadcast if an Ajax request is started a...

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.

ajax参数:

ajax事件与参数详解

ajax事件与参数详解

实例:

function getClData() {
    $.ajax({
        type: 'post',
        url: 'ZTest/GetClData',
        data: {
            aps:aps
        },
        beforeSend: function (XMLHttpRequest) {

        },
        success: function (data, textStatus) {
            //访问后台获取计量表数据和值。
            var jsonData = JSON.parse(data);
            alert(jsonData[0]);
        },
        complete: function (XMLHttpRequest, textStatus) {

        },
        error: function () {

        }
    });
}