Skip to Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
118
Chapter 2
So to get around the caching, we have to
change our request URL every time. But... if
we’re talking to the same script, and we’re
not sending in data in the Boards app, how
can we make the URL different?
The browser doesn’t care how the request URL
is different; it just cares that it’s different. So, we
can add a dummy parameter onto the request
URL, and give it a different value every time
we send the request. And, since we don’t want
to write a random number generator, or do any
extra work, we can just grab the current time (in
seconds), and add that to the request URL.
Let’s take a look at how we can x up
getBoardsSold() from Chapter 1:
Sometimes it takes a hack...
function getBoardsSold() {
createRequest();
var url = “getUpdatedBoardSales-ajax.php”;
url = url + “?dummy=” + new Date().getTime();
request.open(“GET”, url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
Remember back in the
old days, when our
request object was
created in a function?
This rst line sets the
URL normally, and the
second line adds a dummy
value to the URL.
Our dummy
parameter has
the current time
as its value.
Now the request URL changes...
getUpdatedBoardSales-ajax.php?dummy=1139262723388
getUpdatedBoardSales-ajax.php?dummy=1139262774440
getUpdatedBoardSales-ajax.php?dummy=1139262797519
...because each time the request URL
is built, the time is slightly different.
Now, no ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content