newmem
newmem

Reputation: 297

jquery ajax request cached

when i request something via ajax if the input is the search the content seems to be cached? do i add a random number at the end of my query?

/search?input=test

to

/search?input=test&random=283928392

i think this would solve my problem. right? how do i write this in javascript

Upvotes: 2

Views: 1592

Answers (3)

sakhunzai
sakhunzai

Reputation: 14470

Another option

a) if you hate maths

  Math.random().toString().split('.')[1]
  i.e. for random number 0.3338502143216556, you will get 3338502143216556

b) if you wants to do maths

parseInt(Math.random() * 100000)
   i.e.  for random number 0.3338502143216556 you will get 33385

Oky my point here is to send a random integer value not a floating value, hope you don't mind :)

Upvotes: 0

Dereleased
Dereleased

Reputation: 10087

While this [edit: Ramblingwood's Solution] solves your immediate problem, the answer to your question of how to get the number there is to use javascript's Math.random();

Mozilla Reference (JavaScript 1.5)

MSDN Reference (JScript 8.0)

Should be identical, but including both for completeness

Upvotes: 0

Alec Gorge
Alec Gorge

Reputation: 17390

At the beginning of your script (before any AJAX) put:

$.ajaxSetup({
  cache: false
});

That will solve your problem because it will automatically add the random number for every jQuery request. If you don't use jQuery for your AJAX this won't work.

Upvotes: 9

Related Questions