Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery 1.5 Ajax Requests, via Deferred Object, to PageMethod Not Executing as Expected
    primarykey
    data
    text
    <p>I have some code where I wish to call a page method for each row in a datatable. Each row contains user information and the page method looks for additional data regarding that user, in a certain time period. If such data exsts, the idea is to then append the data as a new row to the current row. If no such data exists, move on to the next row.</p> <p>I begin my code with:</p> <pre><code> $.when(GetStartDate(), GetEndDate()) .then(function () { GetSchedules(); }) .fail(function () { failureAlertMsg(); }) </code></pre> <p>First I retrieve start and end dates via page methods. This works fine. Then I try to call a method for each datarorow in the table:</p> <pre><code> function GetSchedules() { $('.DataRow').each(function () { GetUserSchedule($(this)); }); } </code></pre> <p>This to works no problem. I pass the current data row to a new function which is:</p> <pre><code> var currDataRow; var currUserID; function GetUserSchedule(dr) { currDataRow = dr; currUserID = currDataRow.find('td').eq(0).text().trim(); $.ajax({ type: "POST", url: "mypagewithjqueryurl.aspx/GenerateUserSchedule", data: "{'StartDate':'" + startDate + "', 'EndDate':'" + endDate + "', 'UserID':'" + currUserID +"'}", //params contentType: "application/json", dataType: "json", success: function () { alert('Succeeded'); }, error: AjaxFailed }); } </code></pre> <p>When I step through the code, the function is called for each row, currDataRow and currUserID is populated as expected, and the ajax call is performed and here is where the problem lies. The call is made but neither success nor error functions are called until the calls are completed for all rows. Then the success method is called for each row but the required data has been lost.</p> <p>How can I restructure my code so that the success function is called for each ajax request?</p> <p>Thanks in advance for any insight.</p>
    singulars
    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