Django的Ajax请求的响应 [英] django ajax request response

查看:145
本文介绍了Django的Ajax请求的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
   Django的文件上传的JSON

你好我用下面的AJAX上传的模板,但我没有得到来自Django的view.What一个反应是错误的here..i没有看到任何警报

Hi am using the following ajax upload from the template but i do not get a response from django view.What is wrong here..i do not see any alert

function ajax_upload(formid)
{
var form = $(formid);
form.ajaxSubmit({
  dataType:  'json',
  success:   function (data) {
  alert("Hereeeeeeee");
  if(data.status == '1')  
  {
     alert("Uploaded Successfull");
  }
  else 
  {
     alert("Uploaded UnSuccessfull :(");
  }
  }
} )   ; 
}

修改 Django的:

EDIT Django:

  def someview(request):
      response_dict={'status':1}
      logging.debug("seen") //This is seen in the logs
      return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')

EDIT1

请也为完整的源$ C ​​$ C看看 Django的文件上传的JSON

Please also for complete source code look at django file upload from json

推荐答案

从code:

form.ajaxSubmit({
  dataType:  'json',
  success:   function (data) {
    alert("Hereeeeeeee");

您的回调对成功的执行,所以我们可以缩小故障,Django的视图的一面。假设一切语法正确,我最好的猜测是,因为你返回JSON数据,你的反应MIMETYPE应该是:

Your callback executes on 'success', so we can narrow down the failure to the django view side. Assuming everything is syntactically correct, my best guess is that since you're returning json data, your response mimetype should be:

mimetype='application/json'.

如果不行,我会建议使用萤火虫的Firefox或开发工具上的Chrome来看看服务器的响应。你应该能够看到一个Django的堆栈跟踪在那里。

If that doesn't work, I would suggest using Firebug on Firefox or Developer Tools on Chrome to look at the server response. You should be able to see a django stacktrace there.

这篇关于Django的Ajax请求的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆