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 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?