In my project I need to call PHP function inside Javascript file. I have a file called Test.php. Inside this file I have function called getValue().This function will return some value:
<? php
function getValue()
{
echo json_encode('84');
}
?>
Also, I have Javascript file called myScript.js. Inside this file I want to call detVale(); and save the return value in var knobValue. I tried this but it did not work
var knobValue;
$.post('Test.php', function(result) {
knobValue=result;
}, 'json');
$.get('Test.php', function(result) {
knobValue=result;
});
$.ajax({
type: 'POST',
url: 'Test.php',
dataType: 'json',
cache: false,
success: function(result) {
knobValue=result;
}
});
statusCode: { 404: function(){alert('404');}, 500: function(){alert('500');}}to start. This is part of how you can identify what the error is.