SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    yui's asyncRequest too fast for mysql

    hi all!

    i have some problems integrating yui with php application.

    i'm using yui's asyncRequest to post data to php script, that will insert/update data in database.

    it looks like that mysql action is slower than yui's rendering, and that leads me to some other problems (wrong resilts on the page).

    can i somehow check if mysql action in finished, and then continue rendering page?

    my approach with asyncRequest is something like:


    Code JavaScript:
    layoutReq = YAHOO.util.Connect.asyncRequest('POST', 'update.php', redirect, postData);
     
    // i need something here, to check if insert/update of mysql table is finished
     
    setLayout(table, 'update', parseInt(id));


    File update.php contains only php functions for updating data in mysql table.


    So nothing spectacular. but i can not get it to work.

    just to mention that js variable redirect is :

    Code JavaScript:
    			var redirect =
    			{
    				success: function(o) {
    					var content;
    					content=o.responseText;
    					document.getElementById('main').innerHTML = content;
    				}, 
    				failure: function(o) {
    					alert('Layout error! Refresh page!');
    				}
    			}



    if you can help me how to check if mysql query is executed, and somehow to force script to wait for it.

    thank you advance!

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I can't help.
    yui are great, but I only use the layout and gird of it.
    For application/blog/cms I only use wordpress. Sometimes I hack the wordpress code and themes.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i guess that i have to implement somehow next stuff:

    http://developer.yahoo.com/yui/examp...ion/abort.html

    but, what i have to do is to wait for successful sql transaction, and then to continue executing my script.

    this really killing me, please if you can help me!

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't your update.php be executing the query before it returns its response? That would mean the redirect success function won't be executed until after the query, and any content update.php returned to it will be fresh.

    Perhaps your update.php is retrieving the data it outputs before it issues the update queries?

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, i think i did it that way:

    Code JavaScript:
    // here i'm sending request
    layoutReq = YAHOO.util.Connect.asyncRequest('POST', 'update.php', redirect, postData);
     
     
    // i need something here, to check if insert/update of mysql table is finished
     
     
    // here is call for JS function that will render my page
    setLayout(table, 'update', parseInt(id));

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Pasting that code again doesn't get us anywhere new. The request completes and calls the success method when a page is returned, which occurs after your PHP code executes. So it's not a case of the request being "too fast"; it waits.

    Whatever problem you're having has to do with what update.php does, or what your success function does with the output of update.php.

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i'll try to explain my system...

    i have file index.php, with:

    Code PHP:
    <?php
    // some php code, db connection etc.
    ?>
     
    		<script type="text/javascript">
    			// dynamiclly load module javascript engine file
    			// thanks to [url]http://www.codehouse.com/javascript/articles/external/[/url]
    			function dhtmlLoadScript(url)
    			{
    				var e = document.createElement("script");
    				e.src = 'javascript/' + url + ".php";
    				e.type="text/javascript";
    				document.getElementsByTagName("head")[0].appendChild(e);
    			}
    		</script>
     
    		<script type="text/javascript">
    			var redirect =
    			{
    				success: function(o) {
    					var content;
    					content=o.responseText;
    					document.getElementById('main').innerHTML = content;
    				}, 
    				failure: function(o) {
    					alert('Layout error! Refresh page!');
    				}
    			}
     
    			var postData;
    			var layoutReq;
     
    			function setLayout(table, layout, id, action, button, actionId) {
    				dhtmlLoadScript(table); // dynamiclly load module javascript engine file
    				postData = 'table=' + table + '&layout=' + layout;
    				if (typeof(id) == 'string') {
    				  postData = postData + '&show=all';	
    				} else if (id != undefined) {
    					postData = postData + '&id=' + id;	
    				}
    				if (action == 'update') postData = postData + '&' + button + '=1' + '&action=' + action + '&id=' + actionId;
    				document.title = postData;
    				document.getElementById('main').innerHTML = '<font color="red"><b>Loading...</b></font>';
    				//alert(layoutReq); <-------- notice this line
    				layoutReq = YAHOO.util.Connect.asyncRequest('POST', 'engine.php', redirect, postData);
    			}
    		</script>




    Then, in separate file is JS function that sends asyncRequest (you know it from my previous posts),

    Code JavaScript:
    layoutReq = YAHOO.util.Connect.asyncRequest('POST', 'module/update.php', redirect, postData);
     
    setLayout(table, 'list', 'all', null, null, null);



    next file is update.php contains only connetcion to database, and correct mysql_query function.


    so, when i post my data, sometimes it works fine, sometimes elements on form show for just a part of a second and then they dissapear.

    and one more thing, notice line on a bottom of a index.php file. if i uncomment alert function, script works fine.

    hope this can lead us to find solution.

    thank you in advance!
    Last edited by copernicks; Aug 31, 2008 at 02:42.


Bookmarks

Posting Permissions

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