-3

I'm trying to create an Ajax function call where the argument q will be dynamically defined, and the $.get function will return either true or false depending on the data returned by the Ajax call.

<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;
               }
    });       
  });
Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166

1 Answers1

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);
}
Ikrom
  • 4,785
  • 5
  • 52
  • 76