tags:

views:

87

answers:

2

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

+6  A: 

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.

Ramblingwood
That is very sweet, I was not aware of that configuration!
Quintin Robinson
It is really helpful in big projects. Any of the options on http://docs.jquery.com/Ajax/jQuery.ajax can be set with this, which can really save time.
Ramblingwood
A: 

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

Dereleased
ok. fair enough.
Ramblingwood
Certainly your solution was the most elegant to the problem at hand (and taught me something new about jQuery), but it's important, when using any framework, I think, to remember the real functions at work here, lest the actual bare-metal of it all become lost to the ages as magic and mirrors.
Dereleased