Side navigation
#1999 closed bug (fixed)
Opened December 03, 2007 10:18PM UTC
Closed December 04, 2007 07:41AM UTC
Ajax: replace cache value in URL when cache === false, type == get and key (_) already exists
Reported by: | emartin24 | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.2.2 |
Component: | ajax | Version: | 1.2.1 |
Keywords: | cache, ajax | Cc: | |
Blocked by: | Blocking: |
Description
I ran into an issue today where the ajax cache prevention parameter (_=(new Date()).getTime()) is being continuously appended to a URL.
I'm using livequery for an ajax call and after a few clicks, I end up with URL's that look like:
http://mysite.com/mypage.html?_=1196716041523&_=1196716462963&_=1196716464245
My expectation would be that jQuery would look to see if this key already existed and if it did, replace the value with a new timestamp.
I've attached a patch. It could be optimized and perhaps changed to use a RegExp, but it works ;)
Thanks,
Eric
Attachments (1)
Change History (4)
Changed December 04, 2007 04:46AM UTC by comment:1
resolution: | → fixed |
---|---|
status: | new → closed |
Changed December 04, 2007 05:32AM UTC by comment:2
resolution: | fixed |
---|---|
status: | closed → reopened |
Thanks - a much more elegant solution =)
There is one issue however, your replace is greedy and will match the rest of the query string. It just needs to be changed from:
var ret = url.replace(/(\\?|&)_=.*(&|$)/, "$1_=" + ts + "$2");
to:
var ret = url.replace(/(\\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2"); // add ? in front of (&|$)
Thanks,
Eric
Changed December 04, 2007 05:38AM UTC by comment:3
Sorry, I mean:
var ret = s.url.replace(/(\\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
That should be s.url.replace, not url.replace
Changed December 04, 2007 07:41AM UTC by comment:4
resolution: | → fixed |
---|---|
status: | reopened → closed |
Thanks for the catch! I actually had that in my test case and apparently it got lost getting in to jQuery. The fix is in [4007].
Fixed in [4006].