Jump to content

Form data not available after submission:


gamesmstr

Recommended Posts

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
}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.