I am getting some data from mysql and sending it to sever using json. But sending data as an array adds backslashes to my results.
PHP:
$result = mysql_query("SELECT location_name, phone_number FROM location WHERE email_id = '[email protected]'");
$result_array = array();
while($row = mysql_fetch_assoc($result))
{
$result_array[] = $row;
}
echo json_encode($result_array);
JS:
$$.ajax({
url: 'http://www.abc.co/SupportData/get_business_locations.php',
type: "POST",
data: {
email: window.localStorage["email"]
},
dataType: "JSON",
success: function (jsonStr) {
console.log(JSON.stringify(jsonStr));
}
});
Output :
[{\"location_name\":\"Bandra\",\"phone_number\":\"\"},{\"location_name\":\"Dadar\",\"phone_number\":\"\"},{\"location_name\":\"ee\",\"phone_number\":\"\"},{\"location_name\":\"ttttt\",\"phone_number\":\"\"}]""
stripslashes(json_encode($result_array))
worked for me!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With