How to convert JSON to plain text?
{"Days":["is not a number"]}
to Days is not a number.
Here is the code:
$('.best_in_place').bind("ajax:error", function(jqXHR,error, errorThrown) {
alert(error.responseText);
});
How to convert JSON to plain text?
{"Days":["is not a number"]}
to Days is not a number.
Here is the code:
$('.best_in_place').bind("ajax:error", function(jqXHR,error, errorThrown) {
alert(error.responseText);
});
Share
Improve this question
edited Sep 9, 2013 at 16:23
insertusernamehere
23.6k10 gold badges91 silver badges128 bronze badges
asked Sep 9, 2013 at 16:16
BrunoBruno
6,47917 gold badges71 silver badges105 bronze badges
1
-
is it always a object with a
key-value
pair, and the value is a array with a length of one? – Math chiller Commented Sep 9, 2013 at 16:20
3 Answers
Reset to default 2Convert the response into JSON object and parse its key-value pair
var error = JSON.parse( error.responseText );
for( var name in error ) {
console.log( name + " " + error[ name ] ); // Days is not a number
}
As you're using jQuery, this might help:
var result = '';
$.each(error.responseText, function(key, value) {
result += key + ' ' + value;
});
This will also work and can easily be adjusted if the response holds multiple key-value-pairs.
Demo
Try before buy
Use json-to-plain-text npm module