2013-03-25 124 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'); 
      } 
     } 
相关问题