I want to parse json data created by PHP json_encode in my front end app, i can't do this:
var data= '<?php echo $jsonarr; ?>';
As it is a Cordova app. Here is my php code:
<?php
$arr_login= array("lname"=>"$rowlname","email"=>"$rowemail","fname"=>"$rowfname","mobile"=>"$rowmobile");
echo json_encode($arr_login);
?>
My ajax code:
$.ajax({
type:"POST",
url: url,
data:data,
success: function(data){
var res = $.trim(data);
if (res == "Password is inccorrect" || res== "Email is inccorrect") {
$("#errmsg").html(data);
}
else{
var response= JSON.parse(data);
alert(response);
//window.open("dashboard.html?sess=logined&","_self");
}
}
});
Now if I alert data it gives me the valid JSON format as sent by PHP, but I need to convert it to javascript object so I can use it in DOM but JSON.parse gives this error in the console:
VM236:14 Uncaught SyntaxError: Unexpected token / in JSON at position 147