Aiax request not ending

I faced a strange situation and despite the fact that I managed to solve it I still need to find the cause of it.

During an ajax request the server returned ‘0’…this had as a result that the ajax request was never concluding/ending.

I managed to solve it with this code-place inside the success function of the $.ajax function.

 if(data==='0')return;

Was the above really necessary?
Does the ajax request not conclude/end when the data returned are not handled somehow in the success callback?

Thanks…

What do you mean by not ending? The request was kept open until it timed out?

To be honest I never waited so long as for the request to timeout.

I used the .always() callback(jquery) to actually test if the request was ending…and it was not.

In addition to that the ajax loading indicator run continuously.

Could you post your Ajax code? I know you’ve found a solution, but I’d like to try and recreate the problem out of curiosity.

here is the code:

    $('#search').on('keyup', function() {
    var searchKeyword = $.trim($(this).val());
    if(searchKeyword!=='')
      {
           $('.content,h4').empty();
          $.ajax({
      type: "POST",
      url: "searchajax.php",
      dataType:"json",
      cache:false,
      data:{"searchKeyword":searchKeyword},
      success:function(data){
        if(data==='0')return;//no results
        else if(data==='false')
        {
        $('#searcherror').html('Ουπς κάτι δεν πήγε καλά...στείλε μήνυμα στο support');
        }
          $.each(data, function() {
        ........//there are some conditionals here that just categorize the search results....I have removed them since they do not play any role in the solution
               })
           },
      error:function(jqXHR, textStatus, errorThrown){ 
 
     $('#searcherror').html('Ουπς κάτι δεν πήγε καλά...στείλε μήνυμα στο support');//κοιτάμε τα αρχεία του server σε αυτην την περίπτωση
} 
        })
      
          }   
    else
    {
        $('.content,h4').html('');
    }
});

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.