I
I
Ilya Pavlov2015-10-29 17:13:57
PHP
Ilya Pavlov, 2015-10-29 17:13:57

In what form to accept Ajax server responses?

In what form to accept AJax server responses?
For example:
when registering, when checking the E-mail address and login for "uniqueness" - an error: there is already an account for this address and this login is already taken. What is the right way to report it? Possible server responses :
"error_check_email|error_check_login"
And then split in places where there is "|" and check values, look for errors?
OR
"l:1|e:1"
l - login
e - E-mail
0 - verification passed
1 - error
Thus, login(l):error(1)
and split it all into an array.

Or are there smarter options?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrew, 2015-10-29
@PiCoderman

habrahabr.ru/post/112960
Data in json and there will be happiness

I
Ilya Beloborodov, 2015-10-29
@kowap

On server:

$result=[
   'vals'=>'hello',
   'some_else'=>'world'
];
echo json_encode($result);

E
entermix, 2015-10-29
@entermix

php.net/manual/en/function.json-encode.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question