I have json parse error, if I request to database. My php code is:
if($result->num_rows){
header('Content-Type: application/json');
echo json_encode(array("msg" => "close"));
$query = "DELETE FROM users WHERE num = '$num' AND password = '$pw'";
$result = $connection->query($query);
}else {
$myArr = array("msg" => "Неверный пароль!");
echo json_encode($myArr);
exit();
}
and Ajax request code is:
function ajaxLoad(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObj = JSON.parse(this.responseText);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
I tried commenting db request exactly this area
$query = "DELETE FROM users WHERE num = '$num' AND password = '$pw'";
$result = $connection->query($query);
, then my code worked well, but I want to make a request. DB request also working correctly, It deletes the row. I want to say that if i use delete request responseText doesn't work, but it works when i comment the delete request.