Javascript 如何停止java脚本函数执行

Javascript 如何停止java脚本函数执行,javascript,ajax,Javascript,Ajax,我认为CheckSecurityForJasperReport应该返回/定义进一步的操作,而不是直接从那里停止。我想到的快速解决方案是这样的- (可以对此进行优化:-) 您正在使用return停止执行,但没有什么可执行的了。我不知道你在问什么..不清楚你在问什么??详细解释。您希望在哪里停止函数的执行?您希望“停止”哪个函数?你可能会问,如何在不等待成功处理程序的情况下取消ajax请求?我认为var security=“true”不应该全局声明或作为参数传递?谢谢,我的问题已经解决了。太好了。!

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


您正在使用
return停止执行,但没有什么可执行的了。我不知道你在问什么..不清楚你在问什么??详细解释。您希望在哪里停止函数的执行?您希望“停止”哪个函数?你可能会问,如何在不等待成功处理程序的情况下取消ajax请求?我认为var security=“true”不应该全局声明或作为参数传递?谢谢,我的问题已经解决了。太好了。!如果您觉得问题解决了,您可以接受正确答案,如果您愿意的话。:-)
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;
                }
            }   
        });     
    }
    }
    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.!    
  }
}