我正在使用jQuery进行AJAX调用,它运行正常。但是,当我使用AngularJS执行相同的AJAX请求时,只要返回成功,我就没问题。但是,如果发生错误,则不会返回任何响应,并且我的浏览器控制台中会显示错误。
jQuery调用:
$.ajax({
type: "POST",
url: myUrl,
data: a javascript object,
dataType: "json",
//if received a response from the server
success: function(response) {
console.log(response,'in success');
callback(response)
},
error: function(response) {
console.log(response.status,'in error');
callback(response)
}
})
AngularJS致电:
$http({
url: myUrl,
method: "POST",
data: $.param(javascriptObject),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
}).success(//reached Here in case of Success
function(data, status, headers, config) {
console.log(response,'in success');
callback(response)
}).error(function(data, status, headers, config) {
//Never Reached Here
console.log(response.status,'in error');
callback(response)
});
MyController:
//some logic
if(flag==false) {
return Response.status(403).entity(msg).build();
} else {
return Response.status(200).entity(msg).build();
}
答案 0 :(得分:3)
试试这个:
import logging
from logging.handlers import SysLogHandler
[...]
default_fmt = logging.Formatter(
'%(name)s:%(levelname)s - %(message).{}s'.format(MAX_LOG_MESSAGE_SIZE)
)
答案 1 :(得分:1)
确保ajax请求的标头。 除非我弄错了,否则angular不会为XMLHttpRequest设置标头,但JQuery会这样做。