Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 在js中取json.php的数据并赋值给js中变量

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

Jun 23, 2016 pm 01:47 PM

想在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>

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Introduction to the Instagram API

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles