Home > Backend Development > PHP Tutorial > 在js中取json.php的数据并赋值给js中变量

在js中取json.php的数据并赋值给js中变量

WBOY
Release: 2016-06-23 13:47:07
Original
1132 people have browsed it

想在js中把json文件查询结果赋值给js的变量,写法不明白,请教了




<script type="text/javascript">	     window.onload = function() {			$.get("json.php",function(json){//获取数据 		    var data = string2Array(json);//转换数组 		    document.write ("111111111111111111111111");		});			//document.write ("111111111111111111111111");	         var R = Raphael("map", 800, 500);	         var fillcolor = "#FFFFFF"; var beijing = "#FF8F59"; var beijing1 = "602"; var beijing2 = "19"; 
Copy after login


回复讨论(解决方案)

在js中 现在得不到json.php查询数据的 (10 20 30 40)值 ,请教 怎么取到值 ,先谢谢了!

已解决

1、把从数据库取到的结果集 放到view层中,并用赋值不同的变量
2、再在js中将js的变量 =上边的变量

$result = array();
   foreach ($query as $v){

    $result[] = $v->data;
    //echo $v->data; 
   echo "
";
   }
 
 ?>

<script> <br /> window.onload = function() { <br /> var _data="<?php echo $ result[3];?>"; <br /> var R = Raphael("map", 800, 500); <br /> var fillcolor = "#FFFFFF"; var beijing = "#FF8F59"; var beijing1 = "602"; var beijing2 = _data; <br /> 。。。。。。。。。。。。。。 <br /> } <br /> </script>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template