gamesmstr Posted December 11, 2008 Share Posted December 11, 2008 I have the following code: The AJAX call seems to be working just fine. but the form data is not available: Can anyone help me? <table align="center" border="1" cellpadding="5" cellspacing="0" width="500"> <tr><td colspan="3" align="center"><b>Warp to Trading Post Location (Costs 30 Energy)</b></td></tr> <tr> <form action="tradingpost.php" onsubmit="javascript:buytrap('warp'); return false;" method="post"> <td>X value : <select name="warpx"> <option value="0">0</option> <option value="100">100</option> <option value="200">200</option> <option value="300">300</option> <option value="400">400</option> <option value="500">500</option> <option value="600">600</option> <option value="700">700</option> <option value="800">800</option> <option value="900">900</option> <option value="1000">1000</option> </select> </td> <td>Y value : <select name="warpy" > <option value="0">0</option> <option value="100">100</option> <option value="200">200</option> <option value="300">300</option> <option value="400">400</option> <option value="500">500</option> <option value="600">600</option> <option value="700">700</option> <option value="800">800</option> <option value="900">900</option> <option value="1000">1000</option> </select> </td> <td> <input type="submit" value="Warp For 30 Energy" /> </td> </form> </tr> </table> And the Ajax: function createXMLHttpRequest() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; } function buytrap(type) { var xmlHttp11 = createXMLHttpRequest(); params = "type=" + type; xmlHttp11.open("POST","ajax/ajax-tradingpost.php", true); xmlHttp11.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp11.onreadystatechange = function() { if(xmlHttp11.readyState == 4 && xmlHttp11.status == 200) { document.getElementById("tpost-window").innerHTML = xmlHttp11.responseText; } } xmlHttp11.send(params); } And finally the function to retrieve the data: //warp function if ($type== "warp"){ $warpx=$_POST["warpx"]; $warpy=$_POST["warpy"]; if ($questrecord[qstatus] != '0'){ echo"<font color=red><center>You are not allowed to warp while you are on a quest!</center></font>"; } elseif ($playerinfo[energy] < 30){ echo"<font color=red><center>You do not have enough Energy to warp!</center></font>"; } else{ echo"<font color=red><center>You have now warped to the trating post located at $warpx,$warpy!</center></font>"; mysql_query("UPDATE outland_user_data set ux='$warpx', uy='$warpy' where id = '$playerinfo[id]'"); // mysql_query("UPDATE userdb set energy=energy-30 where id = '$playerinfo[id]'"); } echo"<br><br>"; ?> <script>refresh_stats();</script> <?php } Quote Link to comment Share on other sites More sharing options...
Maq Posted December 11, 2008 Share Posted December 11, 2008 but the form data is not available: What exactly do you mean? Does it give you an error? Does anything display? Quote Link to comment Share on other sites More sharing options...
gamesmstr Posted December 11, 2008 Author Share Posted December 11, 2008 yes. I get the following: You have now warped to the trading post located at ,! Quote Link to comment Share on other sites More sharing options...
Philip Posted December 16, 2008 Share Posted December 16, 2008 Have you tried to set the content-length and connection headers? xmlHttp11.onreadystatechange = function() { if(xmlHttp11.readyState == 4 && xmlHttp11.status == 200) { document.getElementById("tpost-window").innerHTML = xmlHttp11.responseText; } } xmlHttp11.open("POST", "ajax/ajax-tradingpost.php", true); xmlHttp11.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp11.setRequestHeader("Content-length", params.length); xmlHttp11t.setRequestHeader("Connection", "close"); xmlHttp11.send(params); I could be wrong, considering I haven't used POST in ajax as much as GET, but I've always needed them. 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.