jQuery: The Write Less, Do More JavaScript Library

Ticket #1999 (closed bug: fixed)

Opened 5 months ago

Last modified 5 months ago

Ajax: replace cache value in URL when cache === false, type == get and key (_) already exists

Reported by: emartin24 Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.2.2 Component: ajax
Version: 1.2.1 Keywords: cache, ajax
Cc: Needs: Review

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

ajax_cache.patch (1.3 kB) - added by emartin24 5 months ago.
patch with possible solution

Change History

Changed 5 months ago by emartin24

patch with possible solution

  Changed 5 months ago by davidserduke

  • status changed from new to closed
  • resolution set to fixed

Fixed in [4006].

  Changed 5 months ago by emartin24

  • status changed from closed to reopened
  • resolution deleted

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

in reply to: ↑ description   Changed 5 months ago by emartin24

Sorry, I mean:

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

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

  Changed 5 months ago by davidserduke

  • status changed from reopened to closed
  • resolution set to fixed

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.