Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How to get json data from a string? - bug-code.com Q&A

How to get json data from a string?

0 like 0 dislike
30 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 | 30 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
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

12.7k users

24,788 questions
46,220 answers
0 comments
12,718 users