2011-02-04 7 views
5

単純なAjaxリクエストを作成していますが、何らかの理由でrequest.is_ajaxがfalseを返します。私はjqueryとDjango開発サーバーを使用しています。 Django開発サーバーがAjaxリクエストを処理しない

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

    }); 

}); 

そしてviews.pyで

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

しかし、それは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"へのPOSTは自動的に"/order/start/"にスラッシュでリダイレクトされ、処理中のPOSTが失われます。

JSのURLがスラッシュで終わっていることを確認してください。

+0

ありがとうございます!スラッシュが問題でした – ruskin

関連する問題