2011-01-28 79 views
0

你好,我有被利用$.ajax()最终的结果称为PHP的方法是我返回类似json_encode($insert)的东西,对ajax调用是成功的我提醒返回数据,并得到如下的成功,jQuery的AJAX JSON帮助

{"content":"Helle this is a testasdasdasdsd","retrain":false,"created_at":1296247015,"employers_id":"4"}

然后我尽量缩小我展示做这个html.content但是这将返回时,我提醒为未定义的数据,下面是我的代码

的Javascript:

$('#employer_feed').submit(function(){ 
    $.ajax({ 
     url: '/employer/feed', 
     data: $('#employer_feed').serialize(), 
     type: 'POST', 
     success:function(html) { 
      alert(html); 
      $('#feed').append('<div class="feed_item">'+html.content+'</div>'); 
     } 
    }); 
    return false; 
}); 

PHP:

if($this->f->insert($insert)) { 
       if(is_ajax()) { 
        echo json_encode($insert); 
       } 
      } 

这是$插入的样子,

Array ( [content] => Helle this is a testasdasdasdsd [retrain] => [created_at] => 1296247448 [employers_id] => 4 )

+0

你能告诉我们什么$插入看起来像? – 2011-01-28 20:42:37

回答

3

尝试增加dataType: "json"$.ajax电话。此外,您可能需要从PHP端将Content-Type标头设置为application/json