Note that there are some explanatory texts on larger screens.

plurals
  1. POConsecutive Ajax Calls Return Data Inconsistently
    primarykey
    data
    text
    <p>I have a task to enhance an existing C# SharePoint application which displays schedules for personnel.</p> <p>I don't have the freedome to use a jQuery plugin calendar. I need to stick with the current code but try to apply jQuery to it to speed up the performance. The current aplication rterirves all the schedules at once and then paints them onto the table. The issue is that the data call can be too large and the page takes forever to load. My task is to retrieve the data for individuals one by one and paint them one by one.</p> <p>Currently, I am using the jQuery 1.5 deferred object's 'when' to populate required parameters first, and 'then' with the userids get the users schedule data asynchronosly. Each call returns a dataset containing two datatables... one with user info, and the other containing user's scheduled events. The trouble is that the data comes back inconsistently. When stepping through the code, I see that the user info returned does not always match the event data that should be tied to the user. </p> <p>As I mentioned before, I am using deferred object, have tried it without the object, have uncsuccsessfully tried to add a delay between each data call, and am just getting plain confused. </p> <p>Not sure if anyone can help me, but if you have suggestions, I'd surely appreciate hearing them. Thanks in advance for any ideas.</p> <pre><code> // When page loads $(document).ready(function () { // The following block uses the jQuery.Deferred() object, introduced in jQuery 1.5 // See http://api.jquery.com/category/deferred-object/ // the object allows us to chain callbacks, **in the order specified** // Get date range debugger; //GetStartDate(), GetEndDate() populates date range //PopulateParams() does that for remaining parameters $.when(GetStartDate(), GetEndDate()) .then(function () { PopulateParams(); GetUserSchedule(); }) .fail(function () { failureAlertMsg(); }) }); // Returns schedule for each person listed in between selected start and end dates function GetUserSchedule() { for (var i = 0; i &lt; arrRequests.length; i++) { // Ajax call to web method, passing in string $.ajax({ type: "POST", url: "/_layouts/epas/scheduler/default.aspx/GenerateUserSchedules", data: arrRequests[i], // example data: {"UserId":"6115","startDate":"\"7/1/2011\"","endDate":"\"7/31/2011\"","ddlGroupSelectedItem":"Z8OK","ddlGroupSelectedValue":"Z8OK#","ddlOrgSelectedValue":"2"} contentType: "application/json", dataType: "json", success: SuccessFunction, error: function (d) { alert('Failed' + d.responseText + '\nPlease refresh page to try again or contact administrator'); } }) } } // On successful completion of call to web method, paint schedules into HTML table for each user function SuccessFunction(data) { if (data != null &amp;&amp; data.d != null &amp;&amp; data.d.Temp != null) { // Calls a bunch of functions to paint schedule onto HTML table // Data contains two tables: one contains user info and the other contains rows of info for each event for user // at times, the user info is not the correct user or the events are not correct for user } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload