Multiple simultaneous ajax requests in ExtJS 4

Problem

I have a long import job that I start with an ajax request, it can take several minutes until the request is complete. While this first ajax request is running, I want to look at the server to find out how far the import will disappear, this second request will be executed every 2 seconds or so.

When I use the Ext.Ajax method, the requests seem to be chained - the first ajax request (import) is executed until it is complete, then the second one (import update) will be launched.

I saw that Ext.Ajax is singleton, so maybe the reason. So I tried to create my own Connection objects using Ext.create('Ext.data.Connection') , but it does not work.

My request chain :

  • first request - start
  • first request - end
  • second request - start
  • second request - end

But it should be:

  • first request - start
  • second request - start
  • second request - end
  • ... maybe more second queries
  • first request - end

Question

The browser should be able to handle multiple requests, there should be a limitation inside ExtJS, but I did not find it?


Update 2011-10-16

Answer

The problem is not ExtJS - sorry! It was PHP, my first script works with the session, and the second script also tried to access the session. And since PHP sessions are file-based, the session file was locked from the first script request, and the second script request had to wait until the first release of the session lock.

I solved this with this small piece of code, which I added to my import process (first script) after each line of x:

  $id = session_id(); session_write_close(); sleep(1); session_start($id); 

This way it stops and reloads the session, and another script was able to connect and get session information.

+6
source share
1 answer

Singleton or non-singleton don't even change the way Ext.Ajax . I think this may be due to coding (did you wait for the calls to end?)

Afaik, I have never had this problem before when I make several calls. The only thing that causes calls is the server (PHP), which does not support parallel processing and causes delays, and generates a template like this.

  • Call 1 - launch
  • Challenge 2 - Launch
  • Call 1 is processed on the server, and call 2 is queued.
  • Call 1 - Completed
  • Call 2 is being processed on the server
  • Call 2 - completed

This can be catastrophic if Call 1 takes longer to process than Call 2.

EDIT:

I wrote this short demo so you can feel how it works. Check it out :) Spent me half an hour lol!

+5
source

Source: https://habr.com/ru/post/900104/


All Articles