如何停止javascript函数执行

时间:2014-01-17 06:04:23

标签: javascript ajax

function processJasperReport(filePath, fileName, fileType) {

    CheckSecurityForJasperReport(filePath, fileName, fileType);

    //call another funcation to run report                                          }               

    function CheckSecurityForJasperReport(filePath, fileName, fileType) {

    if(security == "true")
    {
        $.ajax({
            type : "post",
            dataType: "json",
            url :"../CheckExecutePriviledge",
            data: "reportpath="+filePath+"&reportname="+fileName,
            success:function(content)
            {  priviledge=content;  
                if( priviledge==false)
                {
                    alert("You do not have permission to access this report");
                    return;
                }
            }   
        });     
    }
    }

1 个答案:

答案 0 :(得分:1)

我认为CheckSecurityForJasperReport应该返回/定义进一步的操作,而不是直接从那里停止。我想到的快速解决方案是这样的 - (可以优化: - ))

    function CheckSecurityForJasperReport(filePath, fileName, fileType) {
    var priviledge = false;       
            $.ajax({
                type : "post",
                dataType: "json",
                url :"../CheckExecutePriviledge",
                data: "reportpath="+filePath+"&reportname="+fileName,
                success:function(content)
                {  
                   priviledge = content;
                }   
            });           
     return priviledge; 
}

function processJasperReport(filePath, fileName, fileType) {
     // if security is enabled 
var action_go_ahead = CheckSecurityForJasperReport(filePath, fileName, fileType);
if (action_go_ahead){
// proceed 
}else{
// STOP, nothing to do here.!    
  }
}
相关问题