/myFav/jason.htm
http://lefter.googlecode.com/ · HTML · 42 lines · 34 code · 8 blank · 0 comment · 0 complexity · 4eaeeb068e2f289f7afe6b817ae7ea6e MD5 · raw file
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-
- <html>
- <head>
- <title>php json跨域</title>
- <script type="text/javascript">
- function getProfile(str) {
- var arr = str;
- document.getElementById('nick').innerHTML = arr.contact.website;
- }
- </script>
- </head>
-
- <body>
-
-
- <div id="nick"></div>
- <script type="text/javascript" src="http://localhost:60/singel/profile.php.php"></script>
-
- <h3>php.php代码</h3>
- <pre><code>
- < ? php
- $arr = array(
- 'name' => 'luweijun',
- 'nick' => 'lujo',
- 'contact' => array(
- 'email' => 'me@lefter.net',
- 'website' => 'http://lefter.net',
- )
- );
- $json_string = json_encode($arr);
- echo "getProfile($json_string);";
-
- //再次转换用对象的方法访问
- $obj = json_decode($json_string);
- echo ($obj->name)
- ?>
-
- </code></pre>
-
- </body>
- </html>