J
J
Jupiter Max2018-11-07 08:26:00
JSON
Jupiter Max, 2018-11-07 08:26:00

How to extract json data from a string?

Hello.
There is this code:

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

in fact I get a string along with $errormessage $alert: lalalalalalalala{"error":1}
how to extract only {"error":1} from this in jquery or is it impossible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krypt3r, 2018-11-07
@vardoLP

Do something like this.

if ($pass == 1) {
    echo json_encode(['errormessage' => $errormessage, 'alert' => $alert, 'error' => $pass]);
    exit; // или return;
}

Valid JSON will be returned.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question