2011-02-04 4 views
5

간단한 아약스 요청을하고 있는데 request.is_ajax가 false를 반환합니다. 나는 jquery와 Django 개발 서버를 사용하고있다. 장고 개발 서버가 아약스 요청을 처리하지 않음

$('#save').click(
function() 
{ 
    $.ajax({ 
    type: "POST", 
    url: "/order/start", 

    }); 

}); 

그리고 views.py에서

if request.POST and 'save' in request.POST : 
    if request.is_ajax()== True: 

그러나, 그것이 사실 반환하지 않으며, 경우 runserver에 내가 오류가

Exception happened during processing of request from ('127.0.0.1', 1625) 
Traceback (most recent call last): 

    File "c:\python27\lib\SocketServer.py", line 284, in _handle_request_noblock 
    self.process_request(request, client_address) 
    File "c:\python27\lib\SocketServer.py", line 310, in process_request 
    self.finish_request(request, client_address) 
    File "c:\python27\lib\SocketServer.py", line 323, in finish_request 
    self.RequestHandlerClass(request, client_address, self) 
    File "c:\python27\lib\site-packages\django\core\servers\basehttp.py", line 56 
, in __init__ 
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs) 
    File "c:\python27\lib\SocketServer.py", line 641, in __init__ 
    self.finish() 
    File "c:\python27\lib\SocketServer.py", line 694, in finish 
    self.wfile.flush() 
    File "c:\python27\lib\socket.py", line 301, in flush 
    self._sock.sendall(view[write_offset:write_offset+buffer_size]) 
error: [Errno 10053] An established connection was aborted by the software in y 
ur host machine 

답변

15

난 당신이 표준 미들웨어가 활성화되어 있음을 추측보고 settings.APPEND_SLASH은 True (기본값)입니다. 즉, "/order/start"으로 게시하면 "/order/start/"으로 슬래시가 자동으로 리디렉션되고 해당 프로세스에서 POST가 손실됩니다.

JS의 URL이 슬래시로 끝나야합니다.

+0

감사합니다. 슬래시가 문제였습니다. – ruskin

관련 문제