Server side loading - repeated AJAX calls

Server side loading - repeated AJAX calls

arnorbldarnorbld Posts: 110Questions: 20Answers: 1

Hi guys,

I have multiple tables loaded on server side and I've noticed that some of them seem to call the AJAX PHP process code multiple times one after the other, as in 1 millisecond apart. All those tables have filters and sorting enabled, but looking at the $_POST parameters I don't see any difference.

For example:
1. I load the list from AJAX
2. I type in ONE character in a filter.
3. I get two AJAX calls to PHP that are running concurrently.

I realize that if I'm typing multiple characters it will call it multiple times, but when JUST typing one character, I would assume it only would call the AJAX process once. I don't see any difference in those tables.

Are there some conditions where Datatable may be triggering the AJAX loading more often than normal?

It doesn't seem to affect performance, but I have some logging in the back end and I noticed that it became "messed up" when two instances of the AJAX call were being processed at the same time. So I got curious about why this was happening. Note that this is on a local machine with no other users.

Any ideas on why this may be happening? I'm only curious, don't have any issues with it, just found it interesting that I was getting two concurrent AJAX requests.

Best regards,

Answers

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765

    I believe either SearchPanes or SearchBuilder or maybe both will send an extra ajax request on initial load but don't think they cause extra requests after that.

    It sounds like you are referring to using the default global search input with server side processing. Looking at this example the browser's network inspector shows one XHR request sent for each character typed.

    Possibly you have an event handler that executes, maybe search, which is calling draw() or ajax.reload() which will send an ajax request.

    Kevin

  • arnorbldarnorbld Posts: 110Questions: 20Answers: 1

    Hi Kevin,

    Sorry, I wasn't clear - I'm using column filters in a tfoot showing at the top of the table under the headers. I haven't checked this with the search.

    Yep, it sends with each keystroke (unless you add some JQuery code to stop it, which I have done in some cases when dealing with dates) but this was like it sent two requests right on top of each other. I'm not able to duplicate this at will, it SEEMS to happen only after the list has loaded and then on the first character that is typed. I will need to do some more debugging on this see if I can find a pattern. I do have event handlers that trigger a reload of the table, but they shouldn't be firing at this point, but it's quite possible that something happens that triggers a second reload for some reason. Will try to look into this and will let you know what I find!

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    An aspect of this sounds likely to be how our throttle works - it is a throttle, rather than a debounce (which I regret doing it that way - it will change in v2). So when you press a key it will immediately fire off a query (the idea was that it makes it look like something is happening immediately for the end user, rather than waiting to the end of a debounce period).

    Exactly why it would then trigger another call though, I'm not certain. It sounds like event listeners getting mixed up, but I would expect that to happen 100% of the time rather than intermittently if that were the issue.

    We'd need a test case that replicates the issue to be able to say a huge amount more I think.

    Allan

Sign In or Register to comment.