How do I retrieve the value I receive from the php file in json (echoed in id="show_result" from $show) as a php variable? I wanna be able to do further calculations in php on that variable in first.php
Given the expected result of:
{"show":246}
{"show":100}
Use $.getJSON()
to better handle the results:
<script>
var localShow;
$('#number').on('keyup',function(e){
if(e.which == 13){
var get_var_name = $(this).val();
$.getJSON(
'result.php',
{ number:get_var_name },
function(data,status){
console.log(data);
if(status == 'success'){
$('#show_result').text(data.show);
localShow = data.show;
} else{
alert('Status: ' + status);
}
}
});
}
});
</script>
The script should read the JSON and create data
as an object. You can then call show
using dot notation: data.show
should result in the value 246 or 100 depending on the result.
More details: http://api.jquery.com/jquery.getjson/