Getting ERR_EMPTY_RESPONSE on $.POST

前端 未结 5 1919
野的像风
野的像风 2020-12-21 13:06

I have a simple social networking site with chat functionality. I have used $.post a lot in multiple pages. The code works well on all pages except message.php

5条回答
  •  温柔的废话
    2020-12-21 13:35

    Ajax syncronous: Make the ajax call syncronous. This will stop its thread untill the response is back, easy to implement but comes with the downside that the user cannot type anymore untill request is solved

    $.ajax({
            url: 'bbs.php',
            data: {a:a},
            success: function(abc){
                $(".showoff").html(abc);
            },
            async: false
        });
    

    Global variable check: make a global variable that checks the state of previous request and doesn't allow future ones until it is resolved:

    var waiting=false;
    
    $(".abc").keyup(function(){
    
        if(!waiting){
             waiting = true;
             // code
             $.post('bbs.php',{a:a},function(abc){
                $(".showoff").html(abc);
                waiting=false;
             });
        }
     });
    

提交回复
热议问题