BludClart Posted June 17, 2010 Share Posted June 17, 2010 Hey guys, Been a while since i logged on lol, I am having some problems with my buttons, I have made the body start a refresh function every 5 seconds using my ajax script, Also made it so they can post forms using the ajax script, It kind of loops through as the game goes, Problem i have is this: When a user clicks the button in the main div(The game platform) it will work no problem...BUT if they click any other buttons after that they dont react in any way...When they refresh the page they can click another button and so on, I dont know what i am doing wrong but any help would be appreciated!! Thanks :) Quote Link to comment Share on other sites More sharing options...
BludClart Posted June 17, 2010 Author Share Posted June 17, 2010 I have no idea how my post ended up here :S haha Quote Link to comment Share on other sites More sharing options...
Jordan Palmer Posted June 17, 2010 Share Posted June 17, 2010 I'm really no use with Ajax, but it'd probably be a good idea to show us you're function :) Quote Link to comment Share on other sites More sharing options...
BludClart Posted June 17, 2010 Author Share Posted June 17, 2010 Well its the same way for everyone pretty much, But i think it might be my revalidate control =\ I mean it must be able to be done because when i refresh the page the buttons work again but then of course that makes the ajax pointless ROFL XD Quote Link to comment Share on other sites More sharing options...
LordDan Posted June 17, 2010 Share Posted June 17, 2010 I've used Ajax quite a bit, moved to jQuery Ajax since, but can use both. I would help, but unfortunately, I'm not Psychic.... Code? Also, is this your own code or part of an OpenSource project you downloaded? Also, use Firefox and download FireBug, it's essential for Client Side debugging.. I would have avoided all Client code if it wasn't for FireBug. Quote Link to comment Share on other sites More sharing options...
BludClart Posted June 17, 2010 Author Share Posted June 17, 2010 <?php echo "<meta http-equiv = \"Pragma\" content = \"no-cache\"> <meta http-equiv = \"Cache-Control\" content = \"must-revalidate\"> <center> <script type=\"text/javascript\"> var f = false; var waittime = 5000; var pauserefresh = false; function typingOn() { pauserefresh=true; } if(pauserefresh != true) { function autoRefresh() { clearTimeout(); if(pauserefresh != true) { setTimeout('refreshPoker(\"#\")',5000); } } function postFormAjax(url, formname) { var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\"); } if (!f && xmlhttp) { var fields = new Array(); if(formname) { var ajax = formname; } //loop through form elements and retrieve field NAMEs and Values for (var x = 0; x < eval(\"document.\"+ajax+\".elements.length\"); x++) { // join them into a string. eval(\"fields.push(document.\"+ajax+ \".elements[x].name+'='+document.\" +ajax+\".elements[x].value)\"); } elem = 'errors'; var sendf = fields.join('&'); xmlhttp.open(\"POST\", url, true); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4) { if(xmlhttp.status == 200) { results = xmlhttp.responseText; var para = document.getElementById('errors'); para.innerHTML = results; f = false; // re activate the AJAX function } } } xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send(sendf); f = true; if(pauserefresh != true) { refreshPoker(\"#\"); } } } function refreshPoker(url) { var xmlhttp; if(window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\"); } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { document.getElementById(\"pokermain\").innerHTML = ''; document.getElementById(\"pokermain\").innerHTML = xmlhttp.responseText; } } xmlhttp.open(\"GET\", url, true); xmlhttp.send(null); if(pauserefresh != true) { autoRefresh(); } } } </script>"; ?> This is what im including as the ajax, Whats wrong is i have to refresh the page everytime i want to be able to push a button =\ Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted June 17, 2010 Share Posted June 17, 2010 first of all why makin a PHP which generate a static JS code? also, just quicly I didn't saw the html for the buttons. Quote Link to comment Share on other sites More sharing options...
BludClart Posted June 17, 2010 Author Share Posted June 17, 2010 first of all why makin a PHP which generate a static JS code? also, just quicly I didn't saw the html for the buttons. I guess i could just put the ajax straight into the file that they are on when playing the game, This is the html buttons :) $options = "<td align = 'center' width = '25%'><form method = 'post' name = 'check_btn'> <input type = 'button' name = 'check_btn' value = 'Check' onClick=\"postFormAjax('ptable.php?XID=".$_GET['XID']."', 'check_btn');\"></form></td> <td align = 'center' width = '25%'><form method = 'post' name = 'fold_btn'> <input type = 'button' name = 'fold_btn' value = 'Fold' onClick=\"postFormAjax('ptable.php?XID=".$_GET['XID']."', 'fold_btn');\"></form></td> <td align = 'center' width = '50%'><form method = 'post' name = 'bet_btn'><input type = 'text' name = 'bet_amt' value = '' onkeypress=\"typingOn();\"> <input type = 'button' name = 'bet_btn' value = 'Bet' onClick=\"postFormAjax('ptable.php?XID=".$_GET['XID']."', 'Bet_btn');\"></form></td>"; Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted June 18, 2010 Share Posted June 18, 2010 You don't need any <form method = 'post' name = 'check_btn'> as you will use AJAX to submit. Also your ajax code... sorry seems a bit odd. Why using all those evals? Why not storing the values directly inside JS? Really I think you make the things a lot more complex that what it should :rolleyes: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.