2013-03-25 123 views
0

我有一個簡單的jQuery Ajax表單提交。在提交我的PHP腳本回聲的json_decode($結果)如何提取php返回的json數據並將其顯示在列表中

這是我的AJAX腳本

<script> 
      $("#ajaxquery").live("submit" , function(){ 
      // Intercept the form submission 
      var formdata = $(this).serialize(); // Serialize all form data 

      // Post data to your PHP processing script 
      $.get("getdata.php", formdata, function(data) { 
       // Act upon the data returned, setting it to #success <div> 
       $("#success").html (data); 
      }); 

      return false; // Prevent the form from actually submitting 
     }); 
    </script> 

的問題是,數據顯示在JSON格式。

目前我的輸出是這樣的:

[{"id":4,"comments":1,"likes":15,"books":3,"name":"steve"}] 

我怎樣才能在列表中顯示的數據: -

<ul> 
    <li>id</li> 
    <li>name</li> 
<ul> 

或者是有沒有辦法在一個變量來獲得這些價值?

回答

0

您的成功方法可以是這樣的。這是該方法的屬性數據應該已經是一個合適的JSON對象

success : function(data) { 
      if (data[0].status === 'DONE') { 
       console.log('Done'); 
      } else if (data[0].status === 'IN_PROGRESS') { 
       console.log('In progress'); 
      } 
     } 
相關問題