开发者

Consecutive Ajax Calls Return Data Inconsistently

开发者 https://www.devze.com 2023-03-23 18:58 出处:网络
I have a task to enhance an existing C# SharePoint application which displays schedules for personnel.

I have a task to enhance an existing C# SharePoint application which displays schedules for personnel.

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.

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.

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.

Not sure if anyone can help me, but if you have suggestions, I'd surely appreciate hearing them. Thanks in advance for any ideas.

 //  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 < 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 && data.d != null && data.d.Temp != null) {

        // Calls a bunch of functions to paint schedule onto HTML table
        // Data contains two tables: one contains user 开发者_如何学Pythoninfo 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
    }   

}

0

精彩评论

暂无评论...
验证码 换一张
取 消