How can I get JQGrid to recognize server sent Errors?

后端 未结 8 1058
清酒与你
清酒与你 2020-12-09 16:42

I have a jqgrid that\'s functionning very well.

I was wondering is it possible to catch server sent errors ? how Is it done ?

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 16:55

    function gridCroak(postdata, _url, grid, viewCallBack, debug) {
    $(".loading").css("display", "block");
    $.ajax({
        type: 'POST',
        url: _url,
        data: postdata,
        dataType: "xml",
        complete: function(xmldata, stat){
        if(stat == "success") {
            $(".loading").css("display", "none");
            var errorTag = xmldata.responseXML.getElementsByTagName("error_")[0];
            if (errorTag) {
            $("#ErrorDlg").html(errorTag.firstChild.nodeValue);
            $("#ErrorDlg").dialog('open');
            } else {
            var warningTag = xmldata.responseXML.getElementsByTagName("warning_")[0]; 
            if (warningTag) {
                $("#WarningDlg").html(warningTag.firstChild.nodeValue);
                $("#WarningDlg").dialog('open');
            } else {
                if (debug == true) {
                alert(xmldata.responseText);
                }
                jQuery(grid)[0].addXmlData(xmldata.responseXML);
                if(viewCallBack) viewCallBack();
            }
            }
        } else {
            $("#ErrorDlg").html("Servizio Attualmente Non Disponibile !");
            $("#ErrorDlg").dialog('open');
        }
        }
    });
    }
    

    And In the Grid

    datatype : function(postdata) { gridCroak(postdata, 'cgi-bin/dummy.pl?query=stock', 
                                                        "#list", null, false) },
    

    At the end it does use the same approach I think.

    Thanks all

提交回复
热议问题