json_encode传递给js文件

时间:2013-12-11 14:04:22

标签: ajax getjson json

这里有点新手。

我有以下代码从数据中获取数据并将其格式化为json字符串。但是我怎么能把它放到我的js中来处理那里的代码呢?

PHP / Json编码

<?php include "db.php" ?>

<?php


echo " <br /> Currently Viewing Feedback For 13 <br />  <br />  <br />  <br /> ";



$result = mysqli_query($db_connection, "SELECT * FROM feedback");



while ($row = $result->fetch_assoc()){

  echo "<br /> <br /> <br />";
  echo json_encode($result);
}





?>

1 个答案:

答案 0 :(得分:1)

就在这里,你只是尝试将mysqli_result编码为json,这不是正确的事情。 并且,不要试图将HTML放入您的JSON响应中;)

<?php include "db.php"


echo " <br /> Currently Viewing Feedback For 13 <br />  <br />  <br />  <br /> ";



$result = mysqli_query($db_connection, "SELECT * FROM feedback");

$finalResult = array();

while ($row = $result->fetch_assoc()){

  $finalResult[] = $row;

}

  echo json_encode($finalResult);
?>