Concurrent ajaxRequest Calls

5 posts, 0 answers
  1. Mark
    Mark avatar
    3 posts
    Member since:
    Jul 2011

    Posted 05 Aug 2014 Link to this post

    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?
  2. Mark
    Mark avatar
    3 posts
    Member since:
    Jul 2011

    Posted 05 Aug 2014 in reply to Mark Link to this post

    *CORRECTION*
    ...because the server side processing for row 5 took *less time* than row 1.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 08 Aug 2014 Link to this post

    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.

     
  5. Mark
    Mark avatar
    3 posts
    Member since:
    Jul 2011

    Posted 08 Aug 2014 in reply to Maria Ilieva Link to this post

    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?
  6. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 13 Aug 2014 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017