如果您正在编写返回JSON的处理程序,则它无论如何应返回有效的JSON响应。
应该是这样的:
$response = array();$response["success"] = 0;$response["message"] = "No products found";// include db connect classrequire_once __DIR__ . '/db_connect.php';// connecting to db$db = new DB_ConNECT();// get all products from products table$result = mysql_query("SELECt *FROM products");// check for empty resultif ($result && mysql_num_rows($result) > 0) { // looping through all results // products node $response["products"] = array(); while ($row = mysql_fetch_array($result)) { // temp user array $product = array(); $product["pid"] = $row["pid"]; $product["name"] = $row["name"]; $product["price"] = $row["price"]; $product["created_at"] = $row["created_at"]; $product["updated_at"] = $row["updated_at"]; // push single product into final response array array_push($response["products"], $product); } // success $response["success"] = 1;}// Echo JSON anyway!echo json_enpre($response);die();?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)