0

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?

3
  • possible duplicate of Create JSON object dynamically via JavaScript (Without concate strings) Commented Mar 23, 2015 at 10:10
  • Why are you doing this? Why not output the JSON string using PHP? Commented Mar 23, 2015 at 10:14
  • I dont use php because in my code js i have to call API JS google.maps.geometry Commented Mar 23, 2015 at 10:58

1 Answer 1

0
[{"price":0,"result":"KO - Coordinate di destinazione non valorizzate"}]

Is this what you want? You're seeing the full javascript because you are not calling that php file via a webserver. I think you're trying to access it directly like a local file.

Sign up to request clarification or add additional context in comments.

2 Comments

I call this php from other page php with curl.
Can you try to call this php file directly to see what happens? Check for apache error logs to see what happens.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.