<?php if (isset($_POST['login'],$_POST['password'])){ $a= $db->getRow('select Id_Users,Fam_Users,Name_Users,Otch_Users from Users WHERE Logon_Users=?s AND Password_Users=?s',$_POST['login'],$_POST['password']); } if (empty($a)){ $arg["error"]="Пара логин пароль не верны"; } else { $arg["error"]="0"; $_SESSION['Id_Users']=$a['Id_Users']; $_SESSION['Fam_Users']=$a['Fam_Users']; $_SESSION['Name_Users']=$a['Name_Users']; $_SESSION['Otch_Users']=$a['Otch_Users']; } echo json_encode($arg,JSON_UNESCAPED_UNICODE); So I make a request:
<script language="JavaScript"> var send = document.getElementById("avtoriz"); var xhr = new XMLHttpRequest(); var resp = document.getElementById("resp"); var form = new FormData(); send.onclick= function() { form.append("login",document.getElementById("login").value); form.append("password",document.getElementById("password").value); xhr.open("post","user_iden/autorization",true); xhr.send(form); resp.innerHTML=xhr.status + ': ' + xhr.statusText; }; xhr.onreadystatechange= function() { if (xhr.status != 200) { show(resp); resp.innerHTML=xhr.status + ': ' + xhr.statusText } else { var respons = JSON.parse(xhr.responseText, function(key, value) { if (key == 'error') return new String(value); return value; }); if (respons.error=='0') { location.reload(); } else { resp.innerHTML=respons.error; show(resp); } } }; </script> In principle, everything works as it should, but I do not understand why the error gives
{"error":"Пара логин пароль не верны"}) quite correctly soars. And check for errors here: jsonlint.com - user207618