I'm trying to call php function from my JavaScript script. I've read several questions on how to call a php function using jQuery ajax. I simply copied most of the content and adapted it to fit my script, but somehow it's not working.
Here's my code:
var var1 = document.getElementById("tag").value;
var id = tag.id;
var var3 = tag.checked;
var test = $.ajax({
url: '../PHP/phpFunc.php',
type: 'GET',
data: {param1: var1, param2: id, param3: var3},
complete: function() {
if(window.console) {
console.log("success");
}
},
error: function() {
if(window.console) {
console.log("Error");
}
}
})
and the php code:
<?php
echo "<script>
console.log(\"test\")
</script>";
$var1= $_GET['param1'];
$var2 = $_GET['param2'];
$var3 = $_GET['param3];
$var4 = '../XML/user/'. $var1.'.xml';
?>
the "success" is being printed when the JS function is executed, but php code never returns the desired output.