Re: [問題] 如何使用 jQuery.parseJSON
JSON 不能跨SERVER 只能用JSONP
$.getJSON("http://xxxxx/index.php?jsoncallback=?",
function(data){
});
※ 引述《tabear (胖熊)》之銘言:
: http://api.jquery.com/jQuery.parseJSON/
: 我根據這個網站教學 但是網頁回傳找不到 jQuery.parseJSON 這個function
: 我是從 A.php送到-->B.php再傳回-->A.php
: 我有看回傳值,回傳的很正確 但是無法解析json 請問這如何解決??
: A.php
: <script type="text/javascript" src="jquery.js"></script>
: <script type='text/javascript'>
: abc();
: function abc(){
: createRequest();
: var url='B.php';
: post_str='aaa=1';
: request.onreadystatechange=abc_res;
: request.open('POST',url,true);
: request.setRequestHeader("Content-Type","application/x-www
: -form-urlencoded;charset=UTF-8");
: request.send(post_str);
: }
: function abc_res(){
: if(request.readyState==4){
: if(request.status==200){
: 這行出錯==> var orgData=jQuery.parseJSON(request.responseText);
: ....
: }
: }
: }
: </script>
: B.php 程式如下
: if(isset($_POST['aaa'])){
: $query="SELECT * FROM a_table";
: $res=$db->query($query);
: $his_data=array();
: while($data=$res->fetch()){
: array_push($his_data,$data);
: }
: echo json_encode($his_data);
: }
json_en_c = json_encode($his_data);
jsonp 過來需要用 echo $_GET['jsoncallback']."(".json_en_c.")";
--
█ █ █ http://www.u-tao.tw
█ █ ███ ▄▄█▄ ▄ ▄
█ █ █ █ ▉ █ ▉
█ █ █ █ ▉ █ ▉
◥▇▇▇◤ █ ◢ █ ▋▊ █ ▉
██ ▊█ ◥ ▍█
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.105.192.152
→
12/24 23:18, , 1F
12/24 23:18, 1F
→
12/24 23:19, , 2F
12/24 23:19, 2F
→
12/24 23:19, , 3F
12/24 23:19, 3F
→
12/24 23:20, , 4F
12/24 23:20, 4F
→
12/24 23:21, , 5F
12/24 23:21, 5F
→
12/24 23:23, , 6F
12/24 23:23, 6F
推
12/25 00:07, , 7F
12/25 00:07, 7F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章
33
68