Alright I'm new to ajax but I wanted to know how to go about this using POST I can't find examples and the ones I look at show I'm doing this right but it doesnt seem to be working maybe someone can catch my error.
Index
Code:
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxPlayers = document.getElementById('ajaxPlayers');
ajaxPlayers.innerHTML = ajaxRequest.responseText;
}
}
var limit = document.getElementById('limit').value;
ajaxRequest.open("POST", "players.php", true);
ajaxRequest.send(limit);
}
//-->
</script>
</head>
<body>
<form method=POST>
<table align='center'>
<tr>
<td>
Max Limit:
</td>
<td>
<input type='text' id='limit' onChange=''>
</td>
</tr>
<tr>
<td colspan=2>
<input type='button' value='Retrieve' onClick='ajaxFunction()'>
</td>
</tr>
</table>
</form>
<div id='ajaxPlayers'>Your Results</div>
</body>
</html>
players.php
PHP Code:
<?
include("config.php");
$limit = $_POST['limit'];
echo "limit: $limit";
$query = mysql_query("SELECT * FROM `accounts` ORDER BY `id` ASC LIMIT $limit");
echo("<table>");
while($row = mysql_fetch_array($query))
{
$id = $row['id'];
$username = $row['username'];
$password = $row['password'];
$email = $row['email'];
echo("
<tr>
<td>
$id
</td>
<td>
$username
</td>
<td>
$password
</td>
<td>
$email
</td>
</tr>
");
}
echo("</table> <br> Posts:");
print_r($_POST);
?>
I want to get the limit to pass through but it just doesnt post any ideas?
I know how to do it with GET but I want to learn how to do it with POST.