K
K
Kirill Kirillov2017-08-13 14:59:31
PHP
Kirill Kirillov, 2017-08-13 14:59:31

Ajax not reloading the page?

Here is such a problem.
There is a login page: mysite.com/account/login. When the user enters the account through php and json, the code goes

$result ='Успешно!';
$result = array('eror' =>  $result);
echo  json_encode($result);
exit;

Next, ajax decrypts json and checks result.eror.
result = jQuery.parseJSON(response);
 document.getElementById(result_form).innerHTML = result.eror;
 if(result.eror == 'Успешно!'){
document.location.href = "http://www.mysite.com/index.php"
}

Everything is fine.
But now I have created an input on a modal window, everything is the same. but comes "Success!" and does not reload the page, why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-08-17
@kirillov28

Everything is bad here. I think that the problem is in the encoding and your strings are simply not equal. Return the digital error code and check it. If it's very rude, then so be it.

if (все прошло как надо) {
  $result = array('code' =>  1, 'message' => 'все сработало, как надо');
} else {
  $result = array('code' =>  2, 'message' => 'все очень плохо, произошла такая-то ошибка');
}
echo  json_encode($result);
exit;

if (result.code == '1'){
  window.location.href = "http://www.mysite.ru/index.php"
}
else {
  document.getElementById(result_form).innerHTML = 'Error ' + result.code + ': ' + result.message;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question