[問題] 簡單的json回傳
最近剛學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
09/08 19:43, 1F
→
09/08 19:51, , 2F
09/08 19:51, 2F
※ 編輯: stony1990 來自: 124.9.18.147 (09/08 19:57)
推
09/08 20:12, , 3F
09/08 20:12, 3F
→
09/08 20:16, , 4F
09/08 20:16, 4F
→
09/08 20:20, , 5F
09/08 20:20, 5F
→
09/08 20:32, , 6F
09/08 20:32, 6F
→
09/08 20:58, , 7F
09/08 20:58, 7F
→
09/08 21:01, , 8F
09/08 21:01, 8F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
1
8
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章