如何用jQuery获取django的HttpResponse状态码?
16lz
2021-01-22
My server "return HttpResponse()" when succuess, "return HttpResponse(status=400)" when failed. My client has following jquery ajax function:
我的服务器“返回HttpResponse()”当succuess,“返回HttpResponse(状态= 400)”失败时。我的客户端有以下jquery ajax函数:
$('#submit').click(function(){
$.post("{% url 'addcomment' %}", {msg:$('#newcomment').val()}, function(data,status){
if (status==200) {
location.reload()
} else {
alert("Comment failed")
}
});
});
But the ajax code doesn't work. Any idea?
但是ajax代码不起作用。任何想法?
1 个解决方案
#1
0
As the documentation clearly states, the success callback returns a data
, textStatus
and jqXHR
argument
正如文档明确指出的那样,成功回调返回数据,textStatus和jqXHR参数
http://api.jquery.com/jQuery.post/#jQuery-post-url-data-successdata--textStatus--jqXHR-dataType
If you want the response status get it from the third argument jqXHR.status
如果你想要响应状态从第三个参数jqXHR.status获取它
更多相关文章
- 通过调用返回参数的本地函数来构建Ajax Data部分
- jquerymobile phonegap back按钮获取先前状态
- HTML新手求解。关于CSS对于li标签的active状态的背景颜色
- html5中点击按钮,改变按钮状态效果样式
- WebService Restful方式 Post请求Java无法获取到前台请求的参数,
- html中页面传递参数不用cookie不用缓存,js方法搞定
- 更改在表Django中选择了其中一个按钮时显示的状态
- 问一个高深的问题,静态html页面如何接收来自服务器的参数?
- C 实现HTML5服务时,遇到握手状态的判断问题...