Possible Duplicate:
how to call a PHP function from a form button
I’ve got a button like this:
<form method="post" id="submit" action="script/gen.php">
<input type="button" onClick="getKey()" value="Generate key"/>
This calls a javascript in the same file that looks like this:
<script type="text/javascript">
function getKey() {
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("innhold").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","script/gen.php?returnKey",true);
xmlhttp.send();
}
</script>
I know that this javascript is beeing called, by adding an alert() several places inside the script. The problem occurs when I try to do an isset in my php code:
else if(isset($_GET['returnKey'])) {
returnKey();
}
This function is never beeing called, even if I add a echo before I do the function call returnKey()
Can anyone see where the problem is?
EDIT
This is what the console has to tell me, from chrome:
XMLHttpRequest cannot load file:///C:/wamp/www/Webpanel/script/gen.php?returnKey. Cross origin requests are only supported for HTTP.
Uncaught Error: NETWORK_ERR: XMLHttpRequest Exception 101 index.html:37
getKey index.html:3
EDIT 2
Holy moses, I figured it out. Had to type in localhost/Webpanel in my browser. Its been a long day, so I not quite clear..
Solved to problem:
I tried to open my
index.htmllocally, this is the right way to do it, ofc. Type inlocalhostin the browser. You have to runWAMP.