Simple code, tons of probems (ajax, order of operations, etc.)

Simple code, tons of probems (ajax, order of operations, etc.)

I'm trying to update text based on ajax replies and things aren't going quite as planned.  For the time being, I've commented out the code that references other files.  Why when clicking on an Issue would the "failing" alert pop up before anything else?

  1. <?php
    //require_once './config.php';
    //require_once './like.class.php';

    session_start();
    $_SESSION['User_ID'] = '5';
    ?>
    <html>
    <head>
      <title>Like Test Page</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
      <script type="text/javascript">
        $(document).ready(function() {
          // Bind all "like' clicks
          $(".like").click(function() {
            if (($(this).html() != "You like this")) {
              var boolLiked = false;
              $.get("./like_issue.php", {val:$(this).attr("id")}, function(data) {
    alert('data:--' + data + '--');
                if (data == 'Success') {
    alert('good');
                  boolLiked = true;
                } else {
    alert('bad');
                }
              });


              // On success, update text accordingly
              if (boolLiked) {
    alert('liking...');
                $(this).fadeOut("fast", function() {
                  $(this).html("You like this");
                });
                $(this).fadeIn("fast", function () {});
              } else {
    alert('failing...');
    }
            }
          });
        });
      </script>
    </head>
    <body>
    <a href="./reload.php">reload</a><br /><br />

    <?php
    $arrIssues = array(1, 2, 3, 4, 5); // Emulating output from the issue object

    for ($intIssueID = 1; $intIssueID <= 5; $intIssueID++) {
    //  $objLike = new like($objDB, $intIssueID, $_SESSION['User_ID']);
    //  if ($objLike->is_liked()) {
    //    print '<div class="like" id="like_issue_' . $intIssueID . '">You like issue ' . $intIssueID . '</div>' . "\r\n";
    //  } else {
        print '<div class="like" id="like_issue_' . $intIssueID . '">Issue ' . $intIssueID . '</div>' . "\r\n";
    //  }
    }
    ?>
    </body>
    </html>