Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts

    MySQL Async problem?

    If I'm in a javascript function, and I do the xmlHttp stuff (ajax) to summon some php code that does an SQL UPDATE, how do I know when the update has completed? The problem is I'm doing an SQL SELECT to update the screen after the SQL UPDATE, and it shows the old values but evidently, the UPDATE isn't done yet. (If I stick an Alert("bla bla bla) between ajax calls to the php/sql functions, it works fine).

    Can I check for SQL UPDATE completion? Can I call SQL UPDATE with SYNCH instead of ASYNC? If you can explain this to me there's no need to read the rest of this. It just goes into some more detail of what I'm doing.

    --------------------------------------------------

    I've got a list filled with row data from a db table. Next to the list are a bunch of fields (details of the selected entry). You can edit the fields, hit the submit button, and your changes get recorded. A form/post deal is not used - instead it's AJAX'ed for a nice clean flicker free look.

    The sequence of events are...

    1- User edits the fields
    2- User hits the Submit button
    3- The Submit's "onClick" sends to the javascript function below...

    function UpdatePlayer()
    {
    savedRow = gLastSelectedRow;
    firstname = document.getElementById("id_firstname").value;
    lastname = document.getElementById("id_lastname").value;
    playerid = document.getElementById("id_player_id").value;
    str='fname='+firstname+'^lname='+lastname+^'playerid='+playerid;

    (NOTE: There are a bunch of other fields but for clarity I'll just show the firstname, lastname, and playerid)

    DoAJAX('lib_players/player_update',str);
    RebuildPlayerList();
    HandleRowClick(savedRow);
    DisableSubmit();
    }

    The DoAJAX function does the xmlHttp stuff and passes the field data on to the php code (player_update.php) where the actual sql is done to update the table ...

    <?php
    ...
    $sql = "UPDATE players
    SET firstname = '$fname', lastname = '$lname',
    WHERE id = $playerid";

    $result = mysql_query($sql);

    It all works great except for one problem...
    ...going back to the javascript code above...

    DoAJAX('lib_players/player_update',str);
    RebuildPlayerList();
    HandleRowClick(savedRow);
    DisableSubmit();

    The RebuildPlayerList() function not only redisplays the list, but calls other functions to populate the details (the fields to the right of the list). What I am seeing is that after the SQL Update is called, the old values will be displayed (over the changes you just made) even though the database is updated properly. If I stick an Alert("bla bla bla); after the DoAJAX call, all looks fine.

  • #2
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    OooooK.... I've been doing some AJAX reading and I think I understand the xmlhttp.open function a bit better ... the difference between GET and POST and the all important 3rd arguement, ASYNCH = true/false... but if I set AYNCH to false I still have the same problem. Hmmmm.

  • #3
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    So the function I set for "xmlHttp.onreadystatechange" should tell me the state - when it's completed. but why didn't the asynch=false flag work? just curious. anyway, it's time for bed. i guess there's enough documentation out there on this topic to figure it out. i'll try using the xmlHttp.onreadystatechange next to figure out when to proceed after the SQL UPDATE with the SQL SELECT. Sorry for taking up space having this conversation with myself. If anyone reading this has anything else to add, please do.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •