【问题标题】:How to get json data in for loop for disply [duplicate]如何在for循环中获取json数据以进行显示[重复]
【发布时间】:2018-04-22 04:37:01
【问题描述】:

php代码:

$query = mysqli_query($con,"INSERT INTO tlb_comments(user_id,comments) values ('$vw_id','$name')");
$comments = mysqli_query($con,"SELECT * FROM tlb_comments");
$avatar   = mysqli_query($con,"SELECT * FROM tlb_avatar WHERE `vw_id`='".$vw_id."'");
$avatar_select  =  mysqli_fetch_all($avatar);
$comment_select =  mysqli_fetch_all($comments);
array_push($avatar_select,$comment_select);
echo json_encode($avatar_select);

Jquery Ajax:

$(".comment").click(function() {
    var id = $(this).data("id");
    var name = $("#username_" + id).val();
    if (name == '') {
        alert("Please Fill All Fields");
    } else {

        $.ajax({
            type: "POST",
            url: "comments",
            data: {
                username: name
            },
            success: function(html) {

                $("#cmt_output").html(html);
                console.log(html);
            }
        });
    }
});

Json 数组:

[
   [
      "11",
      "6",
      "1509947417_User_Avatar_2.png"
   ],
   [
      [
         "113",
         "0",
         "6",
         "all of us",
         "0"
      ],
      [
         "114",
         "0",
         "6",
         "all of us",
         "0"
      ],
      [
         "115",
         "0",
         "6",
         "welcome....",
         "0"
      ]
   ]
]

【问题讨论】:

  • 尝试添加一些描述来解释确切的问题
  • 现在显示到我的前端 json 数组数据类型。如何转换数据类型
  • 现在显示到我的前端 json 数组数据类型。如何转换数据文本类型
  • 你的意思是你想将 json 转换为 javascript abject use jQuery.parseJSON()
  • 嗯,好的,我会试试......

标签: php jquery arrays ajax


【解决方案1】:

我认为您必须从 php 返回关联数组,以便您可以轻松地读取带有每个数组元素键的 json 数组...

【讨论】:

    猜你喜欢
    • 2017-03-24
    • 1970-01-01
    • 2016-12-04
    • 2023-04-03
    • 2021-07-17
    • 1970-01-01
    • 2018-09-30
    • 2018-03-25
    • 2016-01-25
    相关资源
    最近更新 更多