0

I am trying to figure out, whats I am doing wrong in following code:

$(function() {
   $(".alert").live('click', function(){
      var id = $(this).closest("tr").attr("id")
      var info = 'id=' + id;
      $.ajax({
         type: "POST",
         url: "http://localhost/app/ajax.php?act=alert",
         data: info,
         success: function(Response){
           }
      });
   alert(Response);
   $(this).hide();
   return false;
   });
});

Return false is not working.

HTML code:

<a href="#" class="alert">Alert</a>
2
  • What is it supposed to do and what does not work? It seems the code is not in success callback... it probably "does not work" because Response is not defined (so it throws an error. Look at the console. Commented May 25, 2011 at 9:38
  • @Felix Kling its not working correct, it redirect page to # , please even check my html code. Commented May 25, 2011 at 9:39

1 Answer 1

3

AJAX is by definition asynchronous.

When your $.ajax call returns the HTTP request will still be getting processed, and therefore Response will not yet be filled.

Put the alert(Response) call inside your success callback to see how it should work.

Sign up to request clarification or add additional context in comments.

2 Comments

yes working now, thanks, so can you clearify more, what i was doing wrong?
you were expecting Response to contain a value before the callback had ever been called.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.