strange variable sent with ajax request

strange variable sent with ajax request

WeeDomWeeDom Posts: 5Questions: 2Answers: 0
edited July 2011 in General
Hi, folks,

I'm working with a strange system where (for old security reasons, probably) CGI parameters need to be registered before they will be accepted.

I'm now trying to do an Ajax request, but I'm seeing a variable getting sent that looks like this: _=1311260749957

Why is that there? Can I get rid of it?

Thanks!
WeeDom

Replies

  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited July 2011
    Hi WeeDom,

    The jQuery .ajax() method has the 'cache' parameter set to false, either explicitly (you put "cache: false" in the object) or implicitly (does DataTables do this by default? I don't remember). So what happens is that jQuery appends a number that is PROBABLY an unprocessed timeStamp to fool the browser into thinking that this is the first time the resource is being asked for. (to the browser, test.php?a=1 and test.php?a=2 are not the same thing.) It will therefore fetch the resource from the server instead of from the local cache.

    I would NOT remove the variable or you will wonder why your data isn't getting updated. I would just get your server-side script to ignore it once it is read in. The end-user won't actually "see" this variable in the URL anyhow, so it should be completely harmless.

    I'm not sure why they decided to "hide" the variable name. Yes, an underscore will never be used by a developer as a variable name, but it would save problems if they would've just named it something descriptive (yet also unlikely to be used by a dev) like "jQueryCacheBuster=" instead. Since the end-user won't see this, who cares what the variable name is? Make it descriptive, jQuery guys! :-)
This discussion has been closed.