0

我的页面上有 2 个 jQuery Ajax Get 方法。仅当 ShowDeviceDetails 中的 Ajax Get 启动而不是 BuildDeviceGrid 方法中的 Ajax Get 时,如何在 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 });


}
4

1 回答 1

0

I hope I understood your question right (feel free to clarify) but you can easily call another function as below:

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

                $("#ajxWaiting").show()

            }
        }

    });

and then put function(){$("#ajxWaiting").show()} inside BuildDeviceGrid.

于 2013-06-08T23:55:16.587 回答