Getting ERR_EMPTY_RESPONSE on $.POST

前端 未结 5 1914
野的像风
野的像风 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:42

    Instead of allowing your server to be spammed, you can remove the handler before the first post and set it back again when the post returns.

    $(document).ready(function(e) {
        var $abc = $('.abc'); //good idea to cache those jQuery selectors!
    
        function abcPost() {
            $abc.off('keyup', abcPost)
            var a = $(this).val();
            $(".showoff").text("wait..");
            $.post('bbs.php', {
                a: a
            },
            function(abc) {
                $(".showoff").html(abc);
                $abc.on('keyup', abcPost)
            });
        }
    
        $abc.on('keyup', abcPost);
    
    });
    

提交回复
热议问题