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获取它

更多相关文章

  1. 通过调用返回参数的本地函数来构建Ajax Data部分
  2. jquerymobile phonegap back按钮获取先前状态
  3. HTML新手求解。关于CSS对于li标签的active状态的背景颜色
  4. html5中点击按钮,改变按钮状态效果样式
  5. WebService Restful方式 Post请求Java无法获取到前台请求的参数,
  6. html中页面传递参数不用cookie不用缓存,js方法搞定
  7. 更改在表Django中选择了其中一个按钮时显示的状态
  8. 问一个高深的问题,静态html页面如何接收来自服务器的参数?
  9. C 实现HTML5服务时,遇到握手状态的判断问题...

随机推荐

  1. PHP中钩子函数的实现与认识
  2. PHP5.4.0新特性研究
  3. 如何在没有显示ID的情况下唯一识别记录?
  4. 来自php表单的样式电子邮件
  5. PHP开发微信支付代码及支付通知处理
  6. 使用CodeIgniter更新MySQL表中的行。
  7. php GD库生成验证码
  8. PHP中出现BOM字符\ufeff,PHP去掉诡异的BO
  9. 从JSON字符串/数组中提取第一个图像
  10. PHP & GD -透明背景填充附近的颜色。