dt614037527
dt614037527
2018-12-14 21:24

将任何json数据放入带有$ .each的标记中

This is my PHP code:

Sessions::sessionStart();
$sql = 'select * from `products` where `id`=?;';
$result = $this->db->prepare($sql);
$result->bindvalue(1, $_SESSION['id']);
$result->execute();
header('Content-Type: application/json');
$data = $result->fetch(PDO::FETCH_OBJ);
$arr=array($data->name,$data->shorttozihat);
echo json_encode($arr);

And this is my AJAX code:

$.ajax({
  dataType: "json",
  url: 'EditPro/InputVal',
  success: function (data) {
    $.each(data, function (key, val) {
      $('p').append(val);
    })
  }
 });

I want every data from json to be stored in one p tag but it puts all json data in one P tag

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

为你推荐