I have a page php with this code:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=drawing,geometry"></script>
<script type="text/javascript">
console.log(" cap in <?php print $_POST['CAP'] ?>");
var v_lat_to = '<?php print $_POST['LAT_TO'].$_GET['LAT_TO'] ?>';
var v_lng_to = '<?php print $_POST['LNG_TO'].$_GET['LNG_TO'] ?>';
var v_lat_from = '<?php print $_POST['LAT_FROM'].$_GET['LAT_FROM'] ?>';
var v_lng_from = '<?php print $_POST['LNG_FROM'].$_GET['LNG_FROM'] ?>';
var v_cap_from = '<?php print $_POST['CAP'].$_GET['CAP'] ?>';
var v_npax = '<?php print $_POST['N_PAX'].$_GET['N_PAX'] ?>';
var v_ora = '<?php print $_POST['ORA'].$_GET['ORA'] ?>';
var v_min = '<?php print $_POST['MIN'].$_GET['MIN'] ?>';
var v_price = 0;
var v_result = "OK";
if(v_lat_to == '' && v_lng_to == ''){
v_result = "KO - Coordinate di destinazione non valorizzate";
console.log("KO - Coordinate di destinazione non valorizzate");
}
else if(v_cap_from == "" && v_lat_from == "" && v_lng_from == ""){
v_result = "KO - Coordinate di partenza non valorizzate";
console.log("KO - Coordinate di partenza non valorizzate");
}
/*
* ...
* ...
* others code with logic javascript
*
*/
// return the output with object json
var jsonObj = [];
var item = {};
item["price"]=v_price;
item["result"]=v_result;
jsonObj.push(item);
document.write(JSON.stringify(jsonObj));
</script>
When I call this php page, I dont find in output the object json, but there is the full code javascript.
Is's correct how create the json from javascript?