PageRenderTime 25ms CodeModel.GetById 18ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/myFav/jason.htm

http://lefter.googlecode.com/
HTML | 42 lines | 34 code | 8 blank | 0 comment | 0 complexity | 4eaeeb068e2f289f7afe6b817ae7ea6e MD5 | raw file
 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 2
 3<html>
 4<head>
 5	<title>php json跨域</title>
 6	<script type="text/javascript">
 7	function getProfile(str) {
 8	    var arr = str;
 9	    document.getElementById('nick').innerHTML = arr.contact.website;
10	}
11</script>
12</head>
13
14<body>
15
16
17<div id="nick"></div>
18<script type="text/javascript" src="http://localhost:60/singel/profile.php.php"></script>
19
20<h3>php.php代码</h3>
21<pre><code>
22< ? php
23$arr = array(
24    'name' => 'luweijun',
25    'nick' => 'lujo',
26    'contact' => array(
27        'email' => 'me@lefter.net',
28        'website' => 'http://lefter.net',
29    )
30);
31$json_string = json_encode($arr);
32echo "getProfile($json_string);";
33
34//再次转换用对象的方法访问
35$obj = json_decode($json_string);
36echo ($obj->name)
37?>
38
39</code></pre>
40
41</body>
42</html>