Får returneret værdi fra php side...
Hvad er det jeg gøre forkert...:(Jeg vil gerne have returneret random nummeret fra php siden...
Bruger Ajax...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script type="text/javascript">
function ajax_post(){
var hr = new XMLHttpRequest();
// opretter variabler som vi sender til php fil
var url = "random.php";
var rN = document.getElementById("random_ID").value;
var vars="random Number"= +rN;
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function(){
if(hr.readyState == 4 && hr.status == 200)
{
alert(hr.responseText);
document.getElementById("status").innerHTML = return_data;
}
}
hr.send(vars);
document.getElementById("status").innerHTML = "processing.....";
}
</script>
</head>
<body>
<?
echo "random Number: <input type='text' id='random_ID' name='random_ID'/>
<input type='submit' value='submit Data' onclick='ajax_post'/>";
?>
</body>
</html>
random.php
<?
$combined = "";
for($i = 0; $i < 10; $i++) {
$randomNumber = rand(0, 9);
$combined = $combined.$randomNumber;
}
echo $combined;
?>