I have a variable in the PHP code called $final_value. I am trying to pass it into a jQuery file using $.ajax but I am unable to do so. Any help will be appreciated.
HTML (test.php)
<body>
<h1>Test</h1>
<p class="result">
<?php
$final_value = 27.00;
echo '<strong>'.$final_value.'</strong>';
echo json_encode($final_value);
?>
</p>
<p id="test"></p>
</body>
jQuery
$(document).ready(function(){
createValue();
function createValue(){
$.ajax({
url: 'http://localhost/test.php',
method: 'post',
dataType: 'json',
success: function(output){
$('#test').append(output);
},
error: function(){
alert('error');
}
});
}
});
dataType; 'html'and see how things work out because my PHP code is part of an HTML file. Still working out how to get the$final_valuefrom HTML though.