如何得到$.获取jquery动态参数变量

how to get $.get jquery dynamic argument variable

本文关键字:动态 参数 变量 jquery 获取 何得      更新时间:2023-09-26

我试图创建一个Ajax函数调用,其中参数q将被动态定义,并且$.get函数将根据Ajax调用返回的数据返回truefalse

<a href="any.php" class="idd" id="1">add score</a>
<a href="any.php" class="idd" id="2">add score</a>
<a href="any.php" class="idd" id="3">add score</a>
$(".idd").click(function(event) {
window.Eid=event.target.id;
//alert(window.Eid);
});
    $.get("getDetails.php",
        { q: window.Eid }, // I want this variable dynamic
        function(m) {
            $(".idd").click(function() {
            //var Eid=event.target.id;
            alert(m);
            if(m>0) {
                return false;
            } else {
                 return true;
               }
    });       
  });
$(function(){
    $(".idd").click(function(event) {
        var id = this.id;
        var ajaxRequest = $.get("getDetails.php", {q: id});
        ajaxRequest.done(function(m){
            alert(m);
            if (m > 0) {
                // do sth here
            } else {
                //do another things here
            }
        });    
        ajaxRequest.fail(function(){
            alert('failed');
        });
        return false;
    });
});
window.onerror = function(errorMessage, url, line) {
    var errorText = 'message: ' + errorMessage + ''nurl: ' + url + ''nline: ' + line;
    alert(errorText);
}