Opened 15 years ago
Closed 15 years ago
#1999 closed bug (fixed)
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 (5)
Changed 15 years ago by
Attachment: | ajax_cache.patch added |
---|
comment:2 Changed 15 years ago by
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
comment:3 Changed 15 years ago by
Sorry, I mean:
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
That should be s.url.replace, not url.replace
comment:4 Changed 15 years ago by
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].
patch with possible solution