【发布时间】:2011-03-01 05:00:10
【问题描述】:
我的模板上有以下 JQuery Ajax 请求,我想将其传递给我的 django 视图,
function loginUser(){
$.ajax({
type:"POST",
url :"/login-user/",
data:"title=ajax call",
datatype:"json",
error:function(data){alert('Error:'+data);}
success:function(data){alert('OK!'+data.message+','+data.code);}
});
}
我的 django 视图如下所示:
def login_user(request):
print "garbage"
print request.GET['title']
return_dict = {'message': 'bla bla bla','code':324}
json=serialize("json",return_dict)
return HttpResponse(json, mimetype="application/x-javascript"
当我调用 ajax 函数时,出现以下错误:
错误:[对象 XMLHttpRequest]
在 django 端,我收到以下错误:
Traceback (most recent call last):
File "c:\python26\lib\site-packages\django\core\servers\basehttp.py", line 281, in run
self.finish_response()
File "c:\python26\lib\site-packages\django\core\servers\basehttp.py", line 321, in finish_response
self.write(data)
File "c:\python26\lib\site-packages\django\core\servers\basehttp.py", line 417, in write
self._write(data)
File "c:\python26\lib\socket.py", line 297, in write
self.flush()
File "c:\python26\lib\socket.py", line 284, in flush
self._sock.sendall(buffer)
error: [Errno 10053] An established connection was aborted by the software in your host machine
这次通话我错过了什么?
加特
【问题讨论】:
标签: javascript jquery ajax django