Jump to content
MakeWebGames

Having trouble with my buttons(Ajax)


BludClart

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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 =\

Link to comment
Share on other sites

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>";
Link to comment
Share on other sites

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:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...