So I'm having trouble with cross browser compatibility. It involves primarily AJAX and since there is not a forum section for that I could see I'm posting here. But I figure it should work anyway since it involves browser, php, JavaScript and AJAX. I have included all the code except the .nav and css. I don't think they are really necessary. This code works perfectly in IE. The problem is Firefox and Crome. I can see that the core of the issue is my AJAX call. When the variable arrives and is placed in the $minlist variable in IE it contains all the compiled information that it is supposed to. It would look something like this 1#20-2#10-3#20. As you can see in the code that string is then broken up using the explode function and processed. When the variable $minlist is gotten ($minlist = $_GET["var3"]) it would only contain "1" in Chrome. The same issue is occurring in Firefox so I think it is just having the same problem Chrome is. Everything from the # sign and past is gone. I assume this is the problem. I know that GET has issues with special characters and POST can fix this. But I have not gotten POST to work yet. I just don't know how to get it to work right. I saw an example in the AJAX section on Send a request to a server that showed this xmlhttp.send("fname=Henry&lname=Ford"); as a way of sending post data. I tried this but I could not get it to work. I could not find an example of how to receive the information at the .php file. I tried xmlhttp.send("varpost=" senddata);in the original file and ($minlist = $_POST["varpost "]in the .php file but that did not work at all. I don't understand everything about AJAX so I know I'm missing something important here. I have read everything I can find and tried everything I can think of and have yet to find a solution. Any help would be greatly appreciated. I hope everyone is doing well.
<html><head><title>Creationism</title><link rel="stylesheet" type="text/css" href="/creationism/style.css" /></head><script type="text/javascript">var xmlhttp, playerid, checkstatus, senddata, holdingvar, coutingvar, namecheck, minidnum;if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest();}else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}function ajaxcall(x){if (x == 1)//runs when the page fist loads{ //get player id from cookie xmlhttp.open("POST", "checkcookie.php?", false); xmlhttp.send(); playerid = xmlhttp.responseText; if (playerid)//if you could get the player id desplay some info { xmlhttp.open("POST", "armydesplay.php?var=" +playerid + "&var2=" +x + "&var3=" +0, false); xmlhttp.send(); document.getElementById("content").innerHTML= xmlhttp.responseText; } else//else send them to the log in page. location.replace("http://www.erothproductions.com/creationism/creationism.php?");}else if (x == 2){ senddata = ""; //zero out send data variable for (coutingvar = 0; coutingvar <= ((document.getElementById('miniontable').rows.length)-1); coutingvar++)//run once for each row in the table, so once for each minion type { //collect data from inputs and compile all that have somthing in them minidnum = document.getElementById('miniontable').rows[coutingvar].id; namecheck = minidnum + "m"; holdingvar = document.getElementById(namecheck).value; if (holdingvar > 0)//if there was somthing in the transfer monster box { if (senddata)//if there was already somthing in senddata senddata += "-" + minidnum + "#" + holdingvar; else //if there was not somnthing in senddata alrady, it just does not add the & before because this is the first entry senddata = minidnum + "#" + holdingvar; } } if (senddata)//they had selected minions { //send data to armydesplay xmlhttp.open("POST", "armydesplay.php?var=" +playerid + "&var2=" +x + "&var3=" +senddata, false); xmlhttp.send(); //reciave return from armydesplay checkstatus = xmlhttp.responseText; if (checkstatus == "error")//check to see if it reciaved error message document.getElementById("error").innerHTML= "There was an error processing your request, please check your numbers and try again<br/>";//if so then set error div with error message else//elese just reload page document.getElementById("content").innerHTML= xmlhttp.responseText; } else//if they did not select any mininions document.getElementById("error").innerHTML= "please select minions you wish to transfer<br/>";//send error message telling the player to select minions to transfer}else if (x == 3){ senddata = ""; //zero out send data variable for (coutingvar = 0; coutingvar <= ((document.getElementById('armytable').rows.length)-1); coutingvar++)//run once for each row in the table, so once for each minion type { //collect data from inputs and compile all that have somthing in them minidnum = document.getElementById('armytable').rows[coutingvar].id; namecheck = minidnum + "a"; holdingvar = document.getElementById(namecheck).value; if (holdingvar > 0)//if there was somthing in the transfer monster box { if (senddata)//if there was already somthing in senddata senddata += "-" + minidnum + "#" + holdingvar; else //if there was not somnthing in senddata alrady, it just does not add the & before because this is the first entry senddata = minidnum + "#" + holdingvar; } } if (senddata)//they had selected minions { //send data to armydesplay xmlhttp.open("POST", "armydesplay.php?var=" +playerid + "&var2=" +x + "&var3=" +senddata, false); xmlhttp.send(); //reciave return from armydesplay checkstatus = xmlhttp.responseText; if (checkstatus == "error")//check to see if it reciaved error message document.getElementById("error").innerHTML= "There was an error processing your request, please check your numbers and try again<br/>";//if so then set error div with error message else//elese just reload page document.getElementById("content").innerHTML= xmlhttp.responseText; } else//if they did not select any mininions document.getElementById("error").innerHTML= "please select minions you wish to transfer<br/>";//send error message telling the player to select minions to transfer}if (document.getElementById("noarmy").value == "yes") document.getElementById("movefrom").disabled=true; if (document.getElementById("nominion").value == "yes") document.getElementById("moveto").disabled=true;}</script><body onload="ajaxcall(1)"><table width= 960px; align="center"><tr align="center" ><td> <div class="header"></div> </td></tr><tr align="center"> <td><div id ="nav"> <?php include("navbar.php");?> </div></td></tr><tr><td align="center" Height= 500px;><div id="content"> <p>loading please wait</p></div></td></tr><tr align="center"><td><div class="footer"><p><a href="mailto:fargore@erothproductions.com">Contact us!</a></p><p>© 2011 Eroth Productions all rights enforced by a severe allergic reaction to peanuts.</p></div></td></tr></table></body></html>
<?phpfunction miniontable($mins, $minorar) // creates formatted table data for minions{$tempids_array = explode("&", $mins); $arraynums = count($tempids_array); $arraynums -=1; for ($arraynums; $arraynums>=0; $arraynums--) { $minion = explode("#", $tempids_array[$arraynums]); switch ($minion[0]) { case 1: $outstuff .= "<tr id=\"1\" align=\"center\" > <td> Homunculi </td> <td> " .$minion[1]. " </td> <td> <input type=\"text\" id=\"1" . $minorar . "\" value =\"0\" size=\"10\" style=\"text-align:center\" /> </td> </tr>"; break; case 2: $outstuff .= "<tr id=\"2\" align=\"center\" > <td> Creature </td> <td> " .$minion[1]. " </td> <td> <input type=\"text\" id=\"2" . $minorar . "\" value =\"0\" size=\"10\" style=\"text-align:center\" /> </td> </tr>"; break; case 3: $outstuff .= "<tr id=\"3\" align=\"center\" > <td> Brain </td> <td> " .$minion[1]. " </td> <td> <input type=\"text\" id=\"3" . $minorar . "\" value =\"0\" size=\"10\" style=\"text-align:center\" /> </td> </tr>"; break; case 4: $outstuff .= "<tr id=\"4\" align=\"center\" > <td> Familiar </td> <td> " .$minion[1]. " </td> <td> <input type=\"text\" id=\"4" . $minorar . "\" value =\"0\" size=\"10\" style=\"text-align:center\" /> </td> </tr>"; break; case 5: $outstuff .= "<tr id=\"5\" align=\"center\" > <td> Talisman </td> <td> " .$minion[1]. " </td> <td> <input type=\"text\" id=\"5" . $minorar . "\" value =\"0\" size=\"10\" style=\"text-align:center\" /> </td> </tr>"; break; } } return $outstuff;}$v = $_GET["var"];$x = $_GET["var2"];$minlist = $_GET["var3"];//connectiong to database$mysqlcreatdata = new mysqli("[color="#000000"]Omitted[/color]", "[color="#000000"]Omitted[/color]", "[color="#000000"]Omitted[/color](", "[color="#000000"]Omitted[/color]");//if it did not work return errorif (mysqli_connect_errno()){printf("Connect failed: %\n", mysqli_connect_error());exit();}//get game account information from the creation player data table$sql = "SELECT [color="#000000"]Omitted[/color], [color="#000000"]Omitted [/color]FROM [color="#000000"]Omitted [/color]WHERE playid = '".$v."'";$res = mysqli_query($mysqlcreatdata, $sql); If ($res) { while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) { $curminions = $newArray['curminions']; $army = $newArray['army']; } }//place add and remove data here, after they run set x to 1 so they can also reload the page, also give warning if change was unsuccsusfulif ($x == 2)// if they are adding to thier amry, perform calculations{$errorvar = 1; //set error variavble to 1 so it is currently not in error//split requested add data$listminions_array = explode("-", $minlist);$arraynums = count($listminions_array);$arraynums -=1;for ($arraynums; $arraynums>=0; $arraynums--)//run loop for each minion selected{ $minion = explode("#", $listminions_array[$arraynums]);//split minion vareable $search = $minion[0] . "#";//create search variable $split = strstr($curminions,$search); //get that minion number and everything after it $temparary_array = explode("&", $split);//explode the split up array, position one should be the desired minion $item_array = explode("#", $temparary_array[0]);//split the disired minion into minion and number possesed if (($errorvar) && $item_array[1] >= $minion[1])//if there is enough of the selected minion and the error variable is still 1 { //reduce from minion amount from current minnions $item_array[1] -= $minion[1];//the second possition should be the number of that minion you have, decrement it if ($item_array[1] == 0)//if you are out of that minion now $replace = ""; else//if you are not out yet $replace = implode ("#", $item_array);//reconstruct the minion with the new total $curminions = str_replace($temparary_array[0],$replace,$curminions);//find the minions old info in the string and replace it with the new info $curminions = str_replace("&&","&",$curminions);//find any occericnes of two & symbols because of running out of a minion and remove them if (strcspn($curminions,"&") == 0)//checks to see if the first character is a & $curminions = substr($curminions,1); //if so then it removes it //to check if there is one one the end we reverse the string, check the beggining again and then reverse it back, yha I know just dont ask it was the best I could come up with $curminions = strrev($curminions); if (strcspn($curminions,"&") == 0)//checks to see if the first character is a & $curminions = substr($curminions,1); //if so then it removes it $curminions = strrev($curminions); //move the minion to army if (strstr($army,$search))//if the minion id is in the minion string { $split = strstr($army,$search); //get that minion number and everything after it $temparary_array = explode("&", $split);//explode the split up array, position one should be the desired minion $item_array = explode("#", $temparary_array[0]);//split the disired minion into minion and number possesed $item_array[1] += $minion[1];//the second possition should be the number of that minion you have, increment it $replace = implode ("#", $item_array);//reconstruct the minion with the new total $army = str_replace($temparary_array[0],$replace,$army);//find the minions old info in the string and replace it with the new info } else//if the minion is new { if ($army)//if you did already have other minions $army .= "&"; $army .= $minion[0] . "#" . $minion[1]; } } else//else set error variable to 0 $errorvar = 0;}$x = 4; //set x to 4 where it will perform database updates and or set the return}if ($x == 3)// if they are removing from thier amry, perform calculations{$errorvar = 1; //set error variavble to 1 so it is currently not in error//split requested add data$listminions_array = explode("-", $minlist);$arraynums = count($listminions_array);$arraynums -=1;for ($arraynums; $arraynums>=0; $arraynums--)//run loop for each minion selected{ $minion = explode("#", $listminions_array[$arraynums]);//split minion vareable $search = $minion[0] . "#";//create search variable $split = strstr($army,$search); //get that minion number and everything after it $temparary_array = explode("&", $split);//explode the split up array, position one should be the desired minion $item_array = explode("#", $temparary_array[0]);//split the disired minion into minion and number possesed if (($errorvar) && $item_array[1] >= $minion[1])//if there is enough of the selected minion and the error variable is still 1 { //reduce from minion amount from current army $item_array[1] -= $minion[1];//the second possition should be the number of that minion you have, decrement it if ($item_array[1] == 0)//if you are out of that minion now $replace = ""; else//if you are not out yet $replace = implode ("#", $item_array);//reconstruct the minion with the new total $army = str_replace($temparary_array[0],$replace,$army);//find the minions old info in the string and replace it with the new info $army = str_replace("&&","&",$army);//find any occericnes of two & symbols because of running out of a minion and remove them if (strcspn($army,"&") == 0)//checks to see if the first character is a & $army = substr($army,1); //if so then it removes it //to check if there is one one the end we reverse the string, check the beggining again and then reverse it back, yha I know just dont ask it was the best I could come up with $army = strrev($army); if (strcspn($army,"&") == 0)//checks to see if the first character is a & $army = substr($army,1); //if so then it removes it $army = strrev($army); //move the minion to minion if (strstr($curminions,$search))//if the minion id is in the minion string { $split = strstr($curminions,$search); //get that minion number and everything after it $temparary_array = explode("&", $split);//explode the split up array, position one should be the desired minion $item_array = explode("#", $temparary_array[0]);//split the disired minion into minion and number possesed $item_array[1] += $minion[1];//the second possition should be the number of that minion you have, increment it $replace = implode ("#", $item_array);//reconstruct the minion with the new total $curminions = str_replace($temparary_array[0],$replace,$curminions);//find the minions old info in the string and replace it with the new info } else//if the minion is new { if ($curminions)//if you did already have other minions $curminions .= "&"; $curminions .= $minion[0] . "#" . $minion[1]; } } else//else set error variable to 0 $errorvar = 0;}$x = 4; //set x to 4 where it will perform database updates and or set the return}if ($x == 4)//eather sends back an error message or runs x1 to recreate screen with new data{if ($errorvar == 0)//if error variable is 0 $outstuff = "error";//set error message and end runelse{ //update both minions and army in database then set x to 1 to resened desplay info $sql = "UPDATE [color="#000000"]Omitted[/color] ET [color="#000000"]Omitted[/color] '". $army ."', [color="#000000"]Omitted[/color]= '". $curminions ."' WHERE [color="#000000"]Omitted[/color]= '". $v ."'"; $res = mysqli_query($mysqlcreatdata, $sql); $x = 1; //set x to 1 so it will reload the page info}}if ($x == 1){$outstuff = "<div id=\"error\"></div><table width= 100%;> <tr> <td align=\"center\" style=\"font-size: 20px;\"> <p>Minions</p><br/> </td> <td align=\"center\" style=\"font-size: 20px;\"> <p>Army</p><br/> </td> </tr> <tr> <td align=\"center\" width= 50%;>";if (!($curminions))// if the player has no minions $outstuff .= "You currently have no minions! <input type=\"hidden\" id=\"nominion\" value =\"yes\"> </td>"; else//if they have minions prepare the table so they can transfer them{ //produce table with current minions $outstuff .= " <input type=\"hidden\" id=\"nominion\" value =\"no\"> <table id=\"miniontable\" width= 80%; border=\"1\">"; $outstuff .= miniontable($curminions, "m"); $outstuff .= "</table></td>";}$outstuff .= "<td align=\"center\" width= 50%;>";if (!($army))// if the player has no army $outstuff .= "You currently have no army! <input type=\"hidden\" id=\"noarmy\" value =\"yes\"> </td>"; else//if they have an army prepare the table so they can transfer them{ //produce table with current army $outstuff .= "<input type=\"hidden\" id=\"noarmy\" value =\"no\"> <table id=\"armytable\" width= 80%; border=\"1\">"; $outstuff .= miniontable($army, "a"); $outstuff .= "</table></td>";}$outstuff .= "</tr> <tr> <td align=\"center\"> <input type=\"submit\" id=\"moveto\" value=\"Move -->\" onclick=\"ajaxcall(2)\"> </td> <td align=\"center\"> <input type=\"submit\" id=\"movefrom\" value=\"<-- Move\" onclick=\"ajaxcall(3)\"> </td> </tr> </table>";$armystr = 0; //variable for calculating total army streangh$minstr_array = explode("&", $army); $arraynums = count($minstr_array); $arraynums -=1; for ($arraynums; $arraynums>=0; $arraynums--) { $minion = explode("#", $minstr_array[$arraynums]); if ($minion[0] == 1)// for minions with points: 16 $armystr += $minion[1] * 16; else if ($minion[0] > 1 && $minion[0] < 6)// for minions with points: 5 $armystr += $minion[1] * 5; } $outstuff .= "<br/><br/>Total Army Strength: " . number_format($armystr);}echo $outstuff;?>