This is a migrated thread and some comments may be shown as answers.

Concurrent ajaxRequest Calls

4 Answers 23 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 05 Aug 2014, 04:37 PM
Hello,

I have a page that populates a RadGrid on load.  The end user has the option to check a box within one or more grid rows.  Upon click of a button, I want to initiate concurrent Ajax requests (one for each row) and allow the page to update (each row) based on when these concurrent requests complete -- which should happen at different times, i.e., it will take varying times for the command to complete for each row.

I have increased the RequestQueueSize on my AjaxManager control to 1000 (I am reading that the real number is considerably lower, i.e, around 4).  That said, it still appears that each request is only made after the previous is complete.  Here is my javascript that makes the ajax request.  I basically iterate over the grid rows, find some relevant controls (a checkbox representing the user selection and an image to show a spinner icon) and then make the request.

        function doCommand(button, args) {
            var grid = $find('<%=myGrid.ClientID %>');
            var masterTable = grid.get_masterTableView();
            var items = masterTable.get_dataItems();

            for (var n = 0; n < items.length; n++) {
                var row = items[n];
                var chkBox = row.findElement("chkCheckStatus");
                var img = row.findElement("myImg");

                if (null != chkBox) {
                    if (chkBox.checked) {
                        var selectedID = row.getDataKeyValue("ID");
                        if (null != img) {
                            img.src = "i/loader.gif";
                        }
                        var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
                        ajaxManager.ajaxRequest("cmd/" + n + "/" + selectedID);
                    }
                }
                else {
                    window.status = "Didn't find the control!";
                }
            }
        }

I handle the ajax call in the RadAjaxManager1_AjaxRequest server side method.  All of this works.

Is there any way for me to fire off many of these requests (sequentially as I iterate the grid rows) and then see the results come in as the commands complete, e.g., row 5 might finish before row 1 because the server side processing for row 5 took longer than row 1?

4 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 05 Aug 2014, 10:43 PM
*CORRECTION*
...because the server side processing for row 5 took *less time* than row 1.
0
Maria Ilieva
Telerik team
answered on 08 Aug 2014, 02:17 PM
Hi Mark,

Unfortunately the required functionality is not supported and it is general Ajax Framework behavior.
You could not execute several requests ate a time and return result for the fastest one on the client. The Ajax framework could only pass subsequent Ajax request one after another and no matter what the return time would be you could not pass subsequent request before the previous one finishes and returns results to the client.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mark
Top achievements
Rank 1
answered on 08 Aug 2014, 02:31 PM
Thank you for the information.

So perhaps a better approach would be to:

1.  Submit all of the requests at once (one ajax call) and set the web page up to refresh grid data via a timer.
2.  Store the requests in a database table and spawn off a thread for each item to process.
3.  When an individual thread completes, it updates the database table row which in turn is displayed on the client web page at its next refresh via the interval.

Would that be a better appraoch?
0
Maria Ilieva
Telerik team
answered on 13 Aug 2014, 11:16 AM
Hi Mark,

The decisions which solution will be used should be taken entirely based on the application requirements and the techniques you prefer to use. My opinion is that the best option will be using a timer and invoke a single Ajax request which will save the additional round trips to the DB.
I would suggest you to try implementing this scenario and let us know in case additional assassinate is needed.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Ajax
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or