【发布时间】:2015-07-10 05:12:15
【问题描述】:
从文件中打印 json 编码数据时,它也会打印脚本。有什么办法可以解决问题
<?php
/*
* Following code will get single product details
* A product is identified by product id (pid)
*/
// array for JSON response
$response = array();
$servername = "mysql11.000webhost.com";
$username = "a1978721_test";
$password = "heavenhell1";
$dbhandle = mysql_connect($servername, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("a1978721_test",$dbhandle)
or die("Could not select examples");
// check for post data
if (isset($_GET["pid"])) {
$pid = $_GET['pid'];
// get a product from products table
$result = mysql_query("SELECT * FROM discount WHERE id = $pid");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$student = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$student["exam_roll"] = $row["exam_roll"];
$student["class_no"] = $row["class_no"];
$student["block_no"] = $row["block_no"];
$student["name"] = $row["name"];
// success
}
$response["success"] = 1;
// user node
$response["student"] = array();
array_push($response["student"], $student);
// echoing JSON response
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No student found";
// echo no users JSON
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No student found";
// echo no users JSON
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
}
header('Content-Type: application/json');
echo json_encode($response);
?>
它的输出是这样的,这正是我不想要的。我需要从输出中删除脚本部分。任何帮助将不胜感激:)
{"success":1,"student":[{"exam_roll":"1212","class_no":"121","block_no":"1221","name":"rohit"}]}
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->
【问题讨论】: