Not sure how to parse this PHP/JSON object in Javascript/jQuery -


so understand, because created json object in php using json_encode , used echo display it, can access directly object in js, this

.done(function(response) {     var result = response;     $(result).hide().prependto('#messages').fadein('slow'); });` 

however, how access data within object? object contains error either true or false, , error_message while contains errors formatted <li>error</li>

php returns - {"error":true,"error_messages":" <li>name short (minimum of 4 characters)<\/li> <li>name short (minimum of 4 characters)<\/li>"}

if server returns correct content-type header (application/json), jquery parse response , give object, can use this:

console.log(response.error_messages); // "<li>name short... 

if server not return correct content-type header, can force issue supplying

datatype: "json" 

in $.ajax call.

either way, json you've quoted in comment on question valid.

so may want:

if (response.error) {     $(response.error_messages).hide().prependto('#messages').fadein('slow'); } else {     // whatever show when it's successful } 

but note #messages must menu, ul, or ol element, since error_message defines li element.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -