-3

我正在尝试创建一个 Ajax 函数调用,其中q将动态定义参数,并且该$.get函数将根据 Ajax 调用返回的数据返回true或返回。false

<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;
               }
    });       
  });
4

1 回答 1

1
$(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);
}
于 2013-05-18T09:47:41.047 回答