I\’m using a map plugin to render some data. The data comes from the DB and into a json file – the script works great. I decided to use the data directly from the php output instead of making a json file. For some reason the javaScript doesn\’t accept the direct php input. I\’m using codeigniter MVC
Here is the sample code that currently works:
$.getJSON(\'_data/index/data.json\', function(data){ ...
Here is what I tried:
var dataMap = \'<? print $mapData;?>\';
$.getJSON(dataMap, function(data){...
* EDIT 2 *
Based on the answers – this option doesn\’t work either.
var dataMap = \'<?php echo $mapData;?>\';
$.get(dataMap, function(data){...
And here is the json data
{\"countries\":{\"AL\":\"1\",\"GB\":\"1\",\"RS\":\"1\",\"BG\":\"6\",\"CA\":\"3\",\"AT\":\"2\",\"CD\":\"1\"}}
EDIT
$mapData is
FOREACH LOOP
$retdata[\'countries\'][] = strtoupper($row->code);
$retdata[\'num\'][] = $row->num;
ENDFOREACH LOOP
$retdata[\'countries\'] = array_combine($retdat[\'code\'], $retdata[\'num\']);
$retdata = json_encode($retdata);
And then it is printed into a file as normal. This is into the model, then I pass it to the controller and then into the view. The string is the same in the $dataMap that I have on file and the one that is being sent to the view.





Rating:
The post jquery – How to use JSON from db/php in JavaScript appeared first on Javascript ASK.
via Javascript ASK http://javascriptask.phpfogapp.com/jquery-how-to-use-json-from-dbphp-in-javascript.html
No comments:
Post a Comment