How to get json data from a string?

0 like 0 dislike
21 views
Hi all.

There is such code:

if($pass==1){ echo $errormessage; echo $alert; die(json_encode(array('error' => $pass))); }


in fact, get the line with $errormessage $alert: lalalalalalalala{"error":1}

how to get only this {"error":1} in jquery or is it impossible?
asked by | 21 views

2 Answers

0 like 0 dislike
Do it like this.
if ($pass == 1) { echo json_encode(['errormessage' => $errormessage, 'alert' => $alert, 'error' => $pass]); exit; // or return; }

Will return valid JSON.
answered by
0 like 0 dislike
So you yourself sent the text with a JSON string?!
Send
echo json_encode(['errormessage' => $errormessage, 'alert' => $alert, 'error' => $pass]);
and you will be happy.
answered by

Related questions

0 like 0 dislike
0 answers
asked Oct 1, 2018 by hexando
0 like 0 dislike
2 answers
asked Nov 7, 2018 by Saharman
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
24,509 questions
45,932 answers
0 comments
352 users