从Ajax成功数据中访问变量?

时间:2016-03-10 12:10:16

标签: javascript php jquery ajax

我需要能够使用我在Ajax请求块之外的Ajax成功数据中设置的变量。

这些是我在上面代码

上面设置的变量
 ruleID     = value['_id'].$id;
 ruleName   = value['rule_name'];
 ruleDesc   = value['rule_desc'];
 ruleType   = value['vali_type'];
 folderID   = value['folder'];
 var folderName

这是我的Ajax请求

 $.ajax({
    type: "POST",
    url: "../ajax/get_folder_name.php",
    data: {
        folderID: folderID
    }, 
    success: function(data) {               
        $.each(data, function(index, value){
            folderName = value.folder_name;
            console.log(folderName);
        })
    },
});

这是我需要能够使用变量folderName的地方(此代码直接位于Ajax请求之下)

 if(ruleErrors[ruleID] !== undefined ){
    var errorCount = ruleErrors[ruleID];

    var rule = "<div class='panel panel-default'>";
    rule += "<div id='"+ruleID+"' class='panel-heading cursor-pointer panel-hover'>";

此行是我需要使用folderName -

的地方
 //rule += "<h4>"+ruleName+"</h4><h5>"+ruleDesc+"( "+folderName+" )</h5><h1 style='float:right; margin-top:-55px;'><span class='label label-danger ruleCount "+ruleID+"'>"+errorCount+"</span></h1>";
    rule += "</div>"; //- Close panel-heading
    rule += "<div class='panel-body "+ruleID+"' style='display:none;'>";
    rule += "<div class='"+ruleID+"table-responsive"+" spinner' style='text-align: center; font-size: 20px;' class='welcome-text'><i class='fa fa-spinner fa-2x fa-spin'></i></div>";
    rule += "<table class='"+ruleID+" table' style='display:none'><thead><tr>";
    rule += "<th>Passenger Name (ID)</th><th>Consultation</th><th>Account Name (ID)</th><th>Tran Type</th><th>Checked Value</th><th>Reason</th><th></th>";
    rule += "</tr></thead><tbody class='"+ruleID+"'></tbody></table>";
    rule += "</div>"; //- Close panel-body
    rule += "</div>"; //- Close panel

    $("#rules").append(rule);
 }

事实证明我无法在Ajax成功模块中使用它,我想不出任何其他方式来获取信息。

0 个答案:

没有答案