jquery - 500服务器错误,我不知道出了什么问题,ajax,django

标签 jquery python ajax django

我有这些代码,我已经研究了几个小时,但我不知道出了什么问题。

我不断收到 500 服务器响应,当我触发 ajax 时,它甚至不会在 View 定义中开始调试。

我真的很茫然,任何帮助都会很棒!

    $('.cheque_info_edit_button').live('click', function(){

var new_cheque = {
    // cheque number is taken from the cell, not input box for this one.
    cheque_no: $(this).closest('td').closest('tr').find('.inv_prof_cheque_no').text(),
    their_bank: $(this).closest('td').closest('tr').find('.new_their_bank_input_ajax').val(),
    our_bank: $(this).closest('td').closest('tr').find('.new_our_bank_input_ajax').val(),
    cash_in_date: $(this).closest('td').closest('tr').find('.new_cash_in_date_input_ajax').val(),
    cheque_amount: $(this).closest('td').closest('tr').find('.new_cheque_amount_input_ajax').val(),
    info_type: 'edit'
   };

    var cheque_json = JSON.stringify(new_cheque);
    $.ajax({
       type: 'POST',
       url: '/best_choose/invoice/profile/inv_add_or_edit_cheque/',
       data: cheque_json,
       success: function(){
       // do stuff
}

更新:我不认为我的观点在语法上有什么问题,所以我把它拿出来并添加了回溯,csrf token 有问题吗?我的所有其他 ajax 函数都可以工作

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/best_choose/invoice/profile/inv_add_or_edit_cheque/

Django Version: 1.3
Python Version: 2.7.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'SY_SYSTEM.sy_system',
 'django.contrib.humanize']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


 Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  178.                 response = middleware_method(request, response)
 File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/middleware/csrf.py" in process_response
  287.             response.content, n = _POST_FORM_RE.subn(add_csrf_field, response.content)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/http/__init__.py" in _get_content
  596.         return smart_str(''.join(self._container), self._charset)

Exception Type: TypeError at /best_choose/invoice/profile/inv_add_or_edit_cheque/
Exception Value: sequence item 0: expected string, NoneType found

最佳答案

我看到了你的jquery代码,不应该有任何错误......

只是一个疯狂的猜测,因为类似的事情之前发生在我身上,我花了一段时间才意识到(忘记了回溯是什么样的)

您可能需要检查您的网址文件,并确保您没有使用相同的网址或现有网址模式的通配符。

关于jquery - 500服务器错误,我不知道出了什么问题,ajax,django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8125987/

相关文章:

python - PyTorch 数据加载器显示字符串数据集的奇怪行为

javascript - 如何正确组合这些 AJAX 和 jQuery 函数?

node.js - Ajax GET 请求 : x-access-token header not recieved in backend

javascript - 检测浏览器是否禁用图像

javascript - Jquery Scroller 需要在到达结束后停止滚动

javascript - 为什么我的 Javascript 在 IE8 中无法运行?

python - 如何每小时从 Linux 终端运行 python 脚本?

javascript - 为什么这个循环不会产生我想要的结果?

python - gem 迷阵风格的游戏比赛

asp.net - 使用 jQuery ajax 时如何在 VB.NET 中捕获异常