douyaosi3164 2016-01-25 17:38
浏览 97
已采纳

如何阻止未格式化的json数组被回显

I have a bookmarks page where images are displayed. The images are being displayed fine however above the images, the array which the images are retrieved from is also displayed such as:

[["1", "img/exampleImage1.png"], ["2", "img/exampleImage2.png"]]

How can I avoid showing this text array but still keep my images?

This is the bookmarks page

  <?php include 'retrieveSymbol.php';?>

          <div id="bookmarkedSymbols"></div>

<script>
//populates product container

$.getJSON("retrieveSymbol.php", function(data){  //retrieves json array
  $.each(data, function(i, field){          //loops through array
    $("#bookmarkedSymbols").append(
             //creates product box filling it with data

       "<img src='" + field[1] + "'" + "id='symbol' alt='stadium'></a>"


    );
  });
});
</script>

This is the retrieve symbol page :

<?php
//connect to the database
$mysqli = NEW MySQLi ('localhost','root','','bookmarkedSymbols');
//query database
$resultSet = $mysqli->query("SELECT * FROM symbols");
//count the rows

if($resultSet->num_rows != 0) {
  //turn the results into an array
  $rows = $resultSet->fetch_all();
  echo json_encode($rows);

}else{
  echo "{no connection}";
}
?>
  • 写回答

2条回答 默认 最新

  • down100009 2016-01-25 17:43
    关注

    In the page with the JS, you don't need to include retrieveSymbol.php since you are calling it with AJAX.

    Remove this:

    <?php include 'retrieveSymbol.php';?>
    

    When you include the php script it is echoing the JSON directly on the page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?