我的響應看起來是這樣的:JSON - 如何提取從Django響應收到的數據?
[{ 「0」: 「[email protected]」},{ 「1」: 「[email protected]」},{ 「2」:「N @ n.com「},{」3「:」[email protected]},{「4」:「[email protected]」},{「5」:「[email protected]」},{「6 「:‘[email protected]’}]
我想通過以下HTML閱讀本:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
document.write('Getting JSON response...');
$.getJSON(<my django url>,
function(data) {
alert("receiveng"+data["0"]);
});
});
</script>
</head>
<body>
</body>
</html>
但我沒有得到任何警告框與數據,只是獲得JSON響應.....行被打印在屏幕上
這是我的返回聲明:
return HttpResponse(simplejson.dumps(result) , content_type='application/json')
切勿在任何類型的回調中使用'document.write':它不應該在執行初始代碼後執行。填寫段落並將其附加到頁面上(或在調試期間使用console.log)。 –
你能向我們展示你的觀點嗎?只是基於看jQuery的小剪輯,它應該工作。 –
答覆在屏幕上打印爲: [{「0」:「[email protected]」},{「1」:「[email protected]」},{「2」:「n @ n。 COM]}] 當我運行的HTML,它只是給出了獲取JSON響應.....打印在它的空白頁面。 – stark