Bug Tracker

Opened 13 years ago

Closed 13 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)

ajax_cache.patch (1.3 KB) - added by emartin24 13 years ago.
patch with possible solution

Download all attachments as: .zip

Change History (5)

Changed 13 years ago by emartin24

Attachment: ajax_cache.patch added

patch with possible solution

comment:1 Changed 13 years ago by davidserduke

Resolution: fixed
Status: newclosed

Fixed in [4006].

comment:2 Changed 13 years ago by emartin24

Resolution: fixed
Status: closedreopened

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 in reply to:  description Changed 13 years ago by emartin24

Sorry, I mean:

var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");

That should be s.url.replace, not url.replace

comment:4 Changed 13 years ago by davidserduke

Resolution: fixed
Status: reopenedclosed

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].

Note: See TracTickets for help on using tickets.