开发者

json request and django response

开发者 https://www.devze.com 2023-02-07 20:17 出处:网络
Why dont i get a response from the server after sending the json request,what am i doinfg wrong $(\"#chat\").submit(function(){

Why dont i get a response from the server after sending the json request,what am i doinfg wrong

  $("#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.
                                                    processRespons开发者_Python百科e(payload);
                                                    },
                    'json'
    );

Django views function:

   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


I'm not sure your syntax for the jQuery POST is correct.

Here's an example:

$.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'
);

The order here is important to remember. The second argument is expected to be the data, but your second argument appears to be a call to alert.

If you're submitting a form, or something from a form, you need to serialize the form element.

To get more control over this process you might want to try using the lower-level $.ajax() function in jQuery.

0

精彩评论

暂无评论...
验证码 换一张
取 消