0

I have a chat page where multiple $.post() are performed at once. The server throws ERR_EMPTY_RESPONSE when multiple $.post() are performed at once.

To minimize, I have created a test page. An ERR_EMPTY_RESPONSE occurs when input is given continuously for some seconds.

The page contents:

a.php

<script>
     $(document).ready(function(e) { $(".abc").keyup(function(){
     var a = $(this).val();
     $(".showoff").text("wait..");
     $.post('bbs.php',{a:a},function(abc){
     $(".showoff").html(abc);
     }); });}); 
</script> 
<input type="textbox" class="abc"> <div class="showoff">Type to Change Me!</div>

bbs.php

<?php
    echo $_POST['a'];
?>

I think this problem might be because multiple request are made before the previous one is responded.
So, how to not allow next post, till previous is resolved? Or, What could be the problem behind this?
Thanks in Advance.

1 Answers1

0

You are sending http requests to your server every time a key is pressed, maybe your server cannot respond to all these requests at same time.

So, you could add an if statement checking if the key pressed is an enter, and after the press of enter disable the input and enable again after the response of the ajax request?

  • If this turns out to be an auto-complete scenario, which it appears to be, this is not an appropriate solution. Code would be nice too, else this should have been a comment – iCollect.it Ltd Jan 18 '16 at 15:10