2011-01-31 17 views
0

私はJSONリクエストを送信した後、サーバーからの応答を取得いけないなぜ、何が間違ってdoinfgいJSONリクエストとレスポンスをDjangoの

$("#chat").submit(function(){ 
      // If user clicks to send a message on a empty message box, then don't do anything. 
      alert($("#msg").val()); 
      alert(url); 
      if($("#msg").val() == "") return false; 


      $.post(url, 
          alert('22'), 

          { 
          time: timestamp, 
          action: "postmsg", 
          message: $("#msg").val() 
        }, 
        function(load) { 
                $("#msg").val(""); // clean out contents of input field. 
                // Calls to the server always return the latest messages, so display them. 
                processResponse(payload); 
                }, 
        'json' 
    ); 

Djangoは機能を見て:

def ajaxcall(request): 
    #I have tried both the return statements and there are no exceptions since see the logging 
    #logging.debug(response) 
    #return HttpResponse(simplejson.dumps(response), mimetype='application/javascript') 
    #return response 

答えて

0

私はありませんjQuery POSTの構文が正しいことを確認してください。

はここに例を示します

$.post(
    '/url/to/post', // url to submit to 
    $("#myform").serialize(), // be sure to serialize form before submitting 
    function(data) { // run after form submit 
     doStuff(); 
}, 
'json' 
); 

ここ順番覚えておくことが重要です。 2番目の引数はデータであると予想されますが、2番目の引数はalertへの呼び出しのようです。

フォームやフォームから何かを送信する場合は、フォーム要素をシリアル化する必要があります。

このプロセスをより詳細に制御するには、jQueryの下位レベルの$ .ajax()関数を試してみてください。

関連する問題