【问题标题】:How to extract json data returned by php and display it in a list如何提取php返回的json数据并显示在列表中
【发布时间】:2013-03-25 11:15:22
【问题描述】:

我有一个简单的 jquery ajax 表单提交。在提交我的 php 脚本回显的 json_decode($result)

这是我的 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>

或者有没有办法在变量中获取这些值?

【问题讨论】:

    标签: jquery ajax json forms


    【解决方案1】:

    【讨论】:

    • 嗨,但是我如何将这些数据“$("#success").html (data)" 传递给 php。我猜(数据)包含所有信息
    【解决方案2】:

    你的成功方法可以是这样的。作为该方法的属性的数据应该已经是适当的 json 对象

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

    【讨论】:

      猜你喜欢
      • 2022-06-10
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 2018-10-08
      相关资源
      最近更新 更多