如何使jQuery ajaxStart区别对待

时间:2013-06-08 23:47:31

标签: jquery ajax jquery-ui

我的页面上有2个jQuery Ajax Get方法。只有在启动ShowDeviceDetails中的Ajax Get而不是Ajax Get我的BuildDeviceGrid方法内部时,如何在我的ajaxStart方法中触发函数?

第一个:

function ShowDeviceDetails(DeviceId) {

    $.ajax({
        type: "GET",
        url: 'GetCompDesktopDetails?id=' + DeviceId,
        dataType: "html",
        success: OnSuccess,
        onStart: function(){$("#ajxWaiting").show()},
        statusCode: {
            200: function () {

                $("#ajxWaiting").show()

            }
        }

    });
}

第二名:

function BuildDeviceGrid() {
    var searchText = "test";
    $("#list").jqGrid({
        url: '/Computer/GetComputerGridData?searchterm=' + searchText + '',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['Id', 'IPAddress', 'HostName'],
        colModel: [
            { name: 'DeviceId', index: 'DeviceId', width: "30%", align: 'left',  searchoptions:{sopt:['cn']}},
            { name: 'IPAddress', index: 'IPAddress', width: "100%", align: 'left', searchoptions: { sopt: ['cn'] } },
            { name: 'HostName', index: 'HostName', width: "120%", align: 'left', searchoptions: { sopt: ['cn'] }}],
        pager: $('#pager'),
        rowNum: 1000,
        rowList: [5, 10, 20, 50],
        sortname: 'DeviceId',
        sortorder: "desc",
        loadonce:true,
        viewrecords: true,
        imgpath: '/Content/jQueryTesting/jquery-ui-1.10.3.custom/css/smoothness/images',
        caption: 'Computers',
        gridview:true,
        multiselect: false,
        navigator: true,
        height: 200,
        width: 600,
        onSelectRow: function (rowId) {
            //alert(rowId)
            var rowData = $('#list').jqGrid('getRowData', rowId)               
            SelectedDeviceId = (rowData['DeviceId'])                
            ShowDeviceDetails(SelectedDeviceId)
        }
    });
    //jQuery("#list").jqGrid('navGrid', '#pager', { add: false, edit: false, del: false }, (filterToolbar, { searchOperators: true }));
    jQuery("#list").jqGrid('filterToolbar', { searchOperators: true });


}

1 个答案:

答案 0 :(得分:0)

我希望我理解你的问题(随意澄清),但你可以轻松地调用另一个函数,如下所示:

$.ajax({
        type: "GET",
        url: 'GetCompDesktopDetails?id=' + DeviceId,
        dataType: "html",
        success: OnSuccess,
        onStart: BuildDeviceGrid,
        statusCode: {
            200: function () {

                $("#ajxWaiting").show()

            }
        }

    });

然后将function(){$("#ajxWaiting").show()}放入BuildDeviceGrid