Always respond with JSON
This commit is contained in:
parent
4551c342b9
commit
7a54476ff1
@ -6,13 +6,13 @@ final class Response {
|
|||||||
|
|
||||||
public static function warning($msg) {
|
public static function warning($msg) {
|
||||||
|
|
||||||
exit('Warning: ' . $msg);
|
exit(json_encode('Warning: ' . $msg));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function error($msg) {
|
public static function error($msg) {
|
||||||
|
|
||||||
exit('Error: ' . $msg);
|
exit(json_encode('Error: ' . $msg));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,15 +26,6 @@ api.post = function(fn, params, callback) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert true and false to real booleans
|
|
||||||
if (data==='true') data = true
|
|
||||||
else if (data==='false') data = false
|
|
||||||
|
|
||||||
// Convert to JSON if string start with '{' and ends with '}'
|
|
||||||
if (typeof data==='string' && data.substring(0, 1)==='{' && data.substring(data.length - 1, data.length)==='}') {
|
|
||||||
data = $.parseJSON(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(data)
|
callback(data)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -49,7 +40,7 @@ api.post = function(fn, params, callback) {
|
|||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: api.path,
|
url: api.path,
|
||||||
data: params,
|
data: params,
|
||||||
dataType: 'text',
|
dataType: 'json',
|
||||||
success,
|
success,
|
||||||
error
|
error
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user