I have a php file that fetches the last price and description of item upon selecting an itemcode from a dropdown list.
The Issue:
When the request is made on the front end, the request is sent to the processing page, which returns a JSON data.
It works perfectly well on my local windows Server. Upon migration to a Live Windows Server, it throws the error like this:
SyntaxError: JSON.parse: unexpected character at line 1 column 9 of the JSON data var data4=JSON.parse(data4);
When I inspect the element using firebug on Firefox browser, I discover that the processing script shows 200K OK 581ms
, which indicate the processing script is fine. But below that is this error of :
SyntaxError: JSON.parse: unexpected character at line 1 column 9 of the JSON data
var data4=JSON.parse(data4);
When I checked further, the processing script which is OK, on the Response and HTML TAB, displays the expected result, which is supposed to show on the requesting (front-end) page.
I need help figuring out why this is happening. Kindly find the pages below.
Front-end page script:
<script type="text/javascript" src="includes/scripts/newJquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("select.partno").change(function(){
var selectedCustomer = $(".partno option:selected").val();
$.ajax({type: "POST",url:"process-grpid.php",data:{custid:selectedCustomer}}).done(function(data4){
var data4=JSON.parse(data4);
//using php-mysql before
if(data4.sta == 0){
$("#desc").html(data4.ref);
$("#purch").html(data4.lprice);
}else{
$("#desc").html(data4.ref);
$("#purch").html(data4.lprice);
}
});
});
});
</script>
Process-grpid.php script:
<?php
if(isset($_POST["custid"])){
include 'includes/session.php';
include 'includes/db_connection.php';
include 'includes/functions.php';
$partid = $_POST["custid"];
if($partid !== 'Select PartNo'){
$gets = "SELECT * FROM tab_stock WHERE itemName='".$partid."'";
$get = mysqli_query($connection,$gets);
$row = mysqli_fetch_array($get);
$desc = $row['description'];
$lprice = $row['Rate'];
if($partid=='N/A'){
$res["sta"]=0;
$res["ref"]="<input type='text' class='desc' name='descr' size='50' required='required'/>";
$res["lprice"]="<input type='text' id='puch' name='lastpur' required='required'/>";
}else{
$res["sta"]=1;
$res["ref"]="<input type='text' value='$desc' class='desc' name='descr' size='50' readonly='readonly' required='required'/>";
$res["lprice"]="<input type='text' id='puch' name='lastpur' value='$lprice' readonly='readonly' required='required'/>";
}
echo json_encode($res);
}
}