I use this simple javascript code to call a php function from javascript.
var a = new XMLHttpRequest();
a.open("GET","save.php");
a.onreadystatechange = function() {
if( a.readyState == 4) {
if( a.status == 200) {
alert("Worked");
}
else alert("HTTP error "+a.status+" "+a.statusText);
}
}
a.send();
In this example I have a php function save()
contained into save.php
file.
I have some questions:
1) How can I call a php function that it is located into the same file where there is the javascript function? (I would to call a php method declared into the same file where there is the javascript caller)
2) Is possible to pass also an php array as parameter?