Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在django项目中使用jQueryAjax_Jquery_Ajax_Django - Fatal编程技术网

在django项目中使用jQueryAjax

在django项目中使用jQueryAjax,jquery,ajax,django,Jquery,Ajax,Django,我尝试使用jquery ajax发布表单 我的脚本是这样的 <script src="{% static "jquery/jquery.min.js" %}"></script> <script> $(document).ready(function(){ $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf_token }}' }

我尝试使用jquery ajax发布表单
我的脚本是这样的

<script src="{% static "jquery/jquery.min.js" %}"></script>
    <script>
        $(document).ready(function(){
            $.ajaxSetup({
                 data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
            });
            $('#comment_form form').submit(function(){
                name = $("#id_name").val();
                email = $("#id_email").val();
                content = $("#id_comment").val();
                $.post("{% url 'blog:comments_upload' %}",
                        {
                            name:name,
                            email:email,
                            content:content,
                        },
                function(data, status){
                    alert("数据" + data + "\n状态" + status);
                });
            });
        });
    </script>

你的问题可能与这个问题类似,你能通过这个问题看到任何问题吗?这里有几个可能的解决方案,这就是我链接到它的原因。张贴您的表单代码。
def comments_upload(request):
    if request.method == 'POST':
        print "it's a test"
        print str(request.POST)
        return HttpResponse("test")
    else:
        return HttpResponse("<h1>test</h1>")
<QueryDict: {u'content': [u'test'], u'csrfmiddlewaretoken': [u'V85BdVwzGY3NUglVfNt4dBWJB0ROQmpv'], u'name': [u'bricks'], u'email': [u'252142844@qq.com']}>
  [11/Apr/2015 00:18:07] "POST /comments_upload/ HTTP/1.1" 200 4
Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 86, in run
    self.finish_response()
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 128, in finish_response
    self.write(data)
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 212, in write
    self.send_headers()
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 270, in send_headers
    self.send_preamble()
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 194, in send_preamble
    'Date: %s\r\n' % format_date_time(time.time())
  File "/usr/lib/python2.7/socket.py", line 324, in write
    self.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
[11/Apr/2015 00:18:07] "POST /comments_upload/ HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 35960)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 593, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python2.7/dist-packages/Django-1.7-py2.7.egg/django/core/servers/basehttp.py", line 129, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 651, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 710, in finish
    self.wfile.close()
  File "/usr/lib/python2.7/socket.py", line 279, in close
    self.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------
[11/Apr/2015 00:18:07] "POST /detail/5/ HTTP/1.1" 200 11797