JSON HTML-?
JSON :
{
"s":0,
"d":{ }
}
So, in your case, you would do something like this (pseudo):
if (StuffIsValid()) {
ResponseWrite('{"s":0,"d":"<html>html code here</html>"}');
} else {
ResponseWrite('{"s":1,"d":{"errlist":["err1","err2"]}}');
}
Of course, you will want to use the built-in JSON library to select your server language instead of using strings.
Then in your jQuery callback successI will do a check on the value of s.
$.ajax({
url: 'url',
dataType: 'json',
success: function(data) {
if (data) {
if (data.s === 0) {
} else if (data.s === 1) {
} else {
}
} else {
}
});
This is especially useful if the user must be logged in to access the page you submit, as you can catch the fact that the returned data was not a JSON object.
source
share