[問題] 簡單的json回傳

看板Ajax作者時間12年前 (2013/09/08 19:42), 編輯推噓1(107)
留言8則, 4人參與, 最新討論串1/2 (看更多)
最近剛學jquery用ajax讀取json格式的資料 自己寫了一個簡單的測試,我聽了bibo9901建議改了url 但卻出現回傳失敗的error視窗,怎麼會這樣呢? --------------------------------------------------------------------------- 檔案一:test_ajax_index.html <meta http-equiv="Content-Type" content="text/html; charset=big-5" /> <script type="text/javascript" src="2.0.3/jquery.min.js"></script> <script> $.ajax({   type: "GET",   url: "test_return_ajax.php",   contentType: "application/json",   dataType: "json",   success: function(output){ var str = output.price + "//" + output.note;     window.alert(str);   },   error: function(){     window.alert("error");   } }); </script> ----------------------------------------------------------------------- 檔案二:test_return_ajax.php <?php $output = array( "price" => 450, "note" => "要等很久"; ); echo json_encode($output); ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.9.18.147

09/08 19:43, , 1F
字串要加引號 -> url: "test_return_ajax.php"
09/08 19:43, 1F

09/08 19:51, , 2F
我加了之後有反應了...但卻是回傳ERROR...
09/08 19:51, 2F
※ 編輯: stony1990 來自: 124.9.18.147 (09/08 19:57)

09/08 20:12, , 3F
檔案二的"note" => "要等很久"; 這個;多了
09/08 20:12, 3F

09/08 20:16, , 4F
原來如此...我好粗心...但怎麼無法顯示中文
09/08 20:16, 4F

09/08 20:20, , 5F
編碼成utf8
09/08 20:20, 5F

09/08 20:32, , 6F
不知道為何我一定要用BIG-5還有顯示UTF-8就完全沒顯示
09/08 20:32, 6F

09/08 20:58, , 7F
我在PHP檔案那裏強制將中文轉成UTF-8就可以正常顯示了
09/08 20:58, 7F

09/08 21:01, , 8F
因為javascript限定用utf-8
09/08 21:01, 8F
文章代碼(AID): #1IB6AP__ (Ajax)
文章代碼(AID): #1IB6AP__ (Ajax)