I'm trying to do what the title says following this example:
How can I call PHP functions by JavaScript?
However I can't get it to work.
Here is the javascript function:
<script>
function errorInProyect(err){
if (document.getElementById("projname").value == ""){
document.getElementById("projname_status").innerHTML = "El nombre del proyecto no puede estar vacio";
}
else{
jQuery.ajax({
type: "POST",
url: 'addproject.php',
dataType: 'json',
data: {functionname: 'prueba'},
success: function (obj) {
document.getElementById("projname_status").innerHTML = "El resultado fue " + obj.result;
}
});
}
}
</script>
And my addproject.php is:
<?php
$res = array();
$res['result'] = "soy la prueba";
json_encode($res);
?>
and I know that the function is being called because the message in case of the empty string is being printed. What am I doing wrong?