2

I have a dashboard where i will call multiple ajax calls in a for loop by only changing the values in the POST data's using the same requesting URL.

The issue is when i first loads the dashboard, where i made multiple ajax calls, when i click for next page - the next page is loaded only after all the dashboard ajax calls are made and success.

In below code i used only simple ajax, i am changing only the POST data in for loop.

$.ajax({
    type: "POST",
    url: "dashboards.php",
    data: {type: typeVal, params: paramsVal },
    success: function(data){  
        console.log('success');
        console.log(data);
    },
    error: function(){
        console.log('error');
    }
});

Please suggests if any alternative way available for this process be done. Thanks in Advance, Kumar.

RK6
  • 424
  • 1
  • 5
  • 23
  • what do you mean by "click for next page" just any 'a' tag? – atmd Jan 07 '15 at 13:47
  • When i logged in my first page is dashboard - if i want to navigate to myprofile page means i will click the next page link (myprofile). Here the issue occurs. myprofile page load after all ajax calls in dashboard completed. – RK6 Jan 07 '15 at 13:50
  • Got a suggestion from http://stackoverflow.com/questions/600494/jquery-automatically-abort-ajaxrequests-on-page-unload. Thank you all – RK6 Jan 07 '15 at 14:08

1 Answers1

0

You could store the request in a varibable

var rq1= $.ajax({
           type: "POST",
           url: "dashboards.php",
           data: {type: typeVal, params: paramsVal },
           success: function(data){  
              console.log('success');
              console.log(data);
           },
           error: function(){
              console.log('error');
           }
});

And then trigger click on next page link and abort the request

rq1.abort();
donald123
  • 5,638
  • 3
  • 26
  • 23
  • How can i use this rq1 variable in next page. can you explain please. – RK6 Jan 07 '15 at 13:53
  • Got a suggestion from http://stackoverflow.com/questions/600494/jquery-automatically-abort-ajaxrequests-on-page-unload. Thank you all. – RK6 Jan 07 '15 at 14:07