2013-01-05 88 views
0

我想從PHP獲取數據與jquery.I寫了這個代碼:JSON和jQuery AJAX

<?php 
     $return=array('content'=>1,'id'=>2,'priority'=>3); 
     echo json_encode($return); 
?> 
jQuery中

$.ajax({ 
type:'post', 
url:'next_prev.php', 
data:{act:act,id:id,priority:priority}, 
dataType: 'json', 
cache: false, 

success:function(data){ 
var obj=jQuery.parseJSON(data) 
$('#content').html(obj.content); 
$('#priority').html(obj.priority); 
$('#id').html(obj.id); 

}, 
}); 

但它並不work.whats錯了嗎?

感謝

在成功回調
+0

我認爲你必須使用var成功函數就像 - obj [content] – sourcecode

+0

你看到了什麼錯誤? – allergic

回答

0

數據根據的dataType格式,即無需parseJSON再次

嘗試刪除var obj=jQuery.parseJSON(data)和使用data.contentdata.priority等直接

+0

他已經解析成功函數中的數據.. – sourcecode

+0

嗨 感謝您的重播,但它不起作用 –

+0

我有一個在PHP頁面的HTML時,刪除它的HTML工作。謝謝很多 –