while printing json encode data file print scripts . can solution problem
<?php /* * following code single product details * product identified product id (pid) */ // array json response $response = array(); $servername = "mysql11.000webhost.com"; $username = "a1978721_test"; $password = "heavenhell1"; $dbhandle = mysql_connect($servername, $username, $password) or die("unable connect mysql"); $selected = mysql_select_db("a1978721_test",$dbhandle) or die("could not select examples"); // check post data if (isset($_get["pid"])) { $pid = $_get['pid']; // product products table $result = mysql_query("select * discount id = $pid"); if (!empty($result)) { // check 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 missing $response["success"] = 0; $response["message"] = "required field(s) missing"; // echoing json response } header('content-type: application/json'); echo json_encode($response); ?> its output comes don't want . need remove script section output . appreciated :)
{"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 -->
the problem
your hosting provider injecting ads response body sending back. there 2 ways can fix this. first remove every response (just remove first n number of lines when javascript parses it), or can find way work around way system implemented.
removing javascript
i'm assuming ingesting response in javascript (however same idea apply anywhere).
// break textblock array of lines var lines = jsonresponse.split('\n'); // remove 1 line, starting @ first position // removing next 4 elements. lines.splice(0,4); // join array single string var jsonresponse = lines.join('\n'); turning off analytics
i'm not sure, i'm guessing using 000webhosts. if are, of methods in here work you:
webhoster inserts javascript brokes code how remove it?
changing appending rules in .htaccess
<filesmatch "\.(php)$"> php_value auto_append_file none </filesmatch>
Comments
Post a Comment