做jquery功能&普通的javascript代码按顺序执行?

时间:2017-03-30 05:53:01

标签: javascript jquery

以下是我遇到的JS代码问题: -

function clearPgnBtnsAndInfo() {
    document.getElementById("lblFromRecNo").innerHTML="";
    document.getElementById("lblToRecNo").innerHTML="";
    document.getElementById("lblTotalRecords").innerHTML="";
    $("#topPgnBtnsDiv").empty(); //removing all the child elements within the div
}

function resetSrchRptDataBtns() {
    document.searchForm.btnView.disabled=false;
    document.searchForm.btnEdit.disabled=false;
    document.searchForm.btnViewSPDet.disabled=false;
    document.searchForm.btnExp2XLSorPDF.disabled=false;
    document.searchForm.btnViewVer.disabled=false;
}

function doSearch(strReqSrcn,strSearchType) { // This function is called on press of a btn on the UI
    closeAlertMsg(); //close error msg if in page DOM
    clearPgnBtnsAndInfo();
    resetSrchRptDataBtns();
    if(strSearchType) 
    {
        var searchFormBean = new SearchFormBean(strSearchType,.,.,.,..); // Building the formBean
        $.ajax({
            url: strThisAppUrl+"/search/getSearchData.do",
            data: JSON.stringify(searchFormBean),
            dataType: "json", 
            contentType: "application/json",
            mimeType: "application/json",
            type: "POST",
            success: function(responseData){
                if(responseData && responseData.searchResult && "success"===responseData.searchResult && responseData.searchResults){
                    var srchListData = responseData.searchResults;
                    var srchListDataTbl = document.getElementById('searchDataTbl');
                    currentSrchListData=srchListData;

                    $("#searchDataTbl").find("tr:gt(0)").remove(); //removing all the table rows except the HEADER row
                    writeSrchDataRpt(srchListData,srchListDataTbl);

                    //--[start] writing the Pagination Info & Buttons --
                    document.getElementById("lblFromRecNo").innerHTML=responseData.fromRecNo;
                    document.searchForm.fromRecNo.value=responseData.fromRecNo;
                    document.getElementById("lblToRecNo").innerHTML=responseData.toRecNo;
                    document.searchForm.toRecNo.value=responseData.toRecNo;
                    document.getElementById("lblTotalRecords").innerHTML=responseData.totalRecords;
                    document.searchForm.totalRecords.value=responseData.totalRecords;

                    var pgnTopBtnsDiv = document.getElementById("topPgnBtnsDiv"); 

                    //JS Code to build & append 4 Pagination Btns to DOM
                    //FIRST-Set Btn                             
                    //PREVIOUS-set Btn
                    //NEXT-set Btn
                    //LAST-set Btn
                    dismissLoadingSpinner();
                }
                else {
                        toggleSrchResultDiv("divHide");
                        dismissLoadingSpinner();
                        showTheMessage("danger",responseData.searchResultMsg);
                    }
                },
                error:function(data,status,er) {
                    toggleSrchResultDiv("divHide");
                    dismissLoadingSpinner();
                    showTheMessage("danger","Error in search request.");
                }
            });
        //--
    }
}

jQuery版本:1.11.3

在mozilla firefox& chrome(尚未在IE中测试)在$("#topPgnBtnsDiv").empty();函数中完成执行行clearPgnBtnsAndInfo()之前处理jquery ajax请求。

jQuery的.empty()函数中是否有任何错误,或者jquery调用可以在该行之前与普通的JS代码混合使用?

在JavaScript中保证调用doSearch(..,..)函数时 - 首先执行函数closeAlertMsg();,然后执行函数clearPgnBtnsAndInfo();,然后函数resetSrchRptDataBtns();为在调用jquery ajax请求代码之前执行或者因为它是ajax请求它不等待它上面的代码完成?

javascript函数是否按顺序同步调用,即一个在另一个函数完成之前不执行?

我的问题的GIF动画: - enter image description here

0 个答案:

没有答案