Forum Moderators: open
I have tried to put together the following AJAX request but it is not working. I keep getting an internal server error 500.
The aim of all this is to do nothing more than send the value of a button to the php script which spits back the value of the button that was clicked.
Here is the javascript portion:
<script type="text/javascript">
function GetValue(v) {
xmlHttpReq = new XMLHttpRequest();
xmlHttpReq.onreadystatechange = handleValue;
xmlHttpReq.open("GET", "updateSite.php?button="+v,true);
xmlHttpReq.send(null);
}
function handleValue() {
if(xmlHttpReq.readyState == REQUEST_COMPLETED) {
if(xmlHttpReq.status == HTTP_OK) {
alert(xmlHttpReq.responseText);
} else {
alert("Network error!");
}
}
}
</script>
Here the html:
<button type="button" onClick="GetValue(this.value)" class="button eins" value="1">
Button 1
</button>
<button type="button" onClick="GetValue(this.value)" class="button zwei" value="2">
Button 2
</button>
<button type="button" onClick="GetValue(this.value)" class="button drei" value="3">
Button 3
</button>
Oh and here is the part in the php:
<?php
Result = $_GET["button"];
echo "You clicked on Button ".Result;
?>
Now I can't seem to get the responseText to be shown in the alert in the Javascript, any ideas?
i.e. when I click on a button nothing happens on the html page (using the Firebug console I can see that there is a response from the php page)