Reputation: 297
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
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
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)
Should be identical, but including both for completeness
Upvotes: 0
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