0

I try to send multiple requests on the same url. I send users.length requests to the server because i need to ban all those users are in this array. The problem is that this code returns me always the same data. I know that i must use promises but i can't convert this code.

for(i = 0; i<selected_users.length; i++)
{
  $.post(webRoot + "ban-user",
  {
    "user-id" : selected_users[i],
    "action-type" : action_type
  },
  function(data,status){
    if(status == "success")
    {
      alert(data);
    }
  }
 });
}
  • 1
    *this code returns me always the same data* May be because the server is responding with the same data? – hr_117 May 02 '16 at 16:21
  • It might be helpful to have a description of what is being sent over the network, or at least what values are supplied to each `$.post` call. As written, this code looks like it will send one request for each member of `selected_users`. If that's not what's happening, you may not be showing the relevant parts of the code. If that *is* what is happening, then perhaps your server is to blame -- it's sending back the same results for different inputs. – apsillers May 02 '16 at 16:21
  • Your code has an extra `}` before the `);` – apsillers May 02 '16 at 16:24
  • As the others said you need to provide more information. What is your server side code? – eko May 02 '16 at 16:32

1 Answers1

0

try using

$.ajaxSetup({ cache: false });

this will prevent caching.

check this answer in SO

Community
  • 1
  • 1
Rifky
  • 1,444
  • 11
  • 26