Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "_=1389258551926" sent as query string parameters on ajax request? [duplicate]

I am using JQuery Ajax to send request to my action class with data: {campaignId: campaignId} but _=1389258551926 also sent as data.

My ajax request function is:

$('#submit').click(function() {
    var campaignId = $('#campaign').val();
    alert("Ajax request ; Camp : " + campaignId);
    $.ajax({
        type: "get",
        url: "getCampData",
        data: {campaignId: campaignId},
        dataType: "json"
    }).done(function(data) {
        alert("Camp List : " + data.campList);
});

Query String parameters:

campaignId=Test&_=1389258551927

Why this extra parameter sent as data?

like image 266
earthmover Avatar asked Jan 09 '14 09:01

earthmover


1 Answers

This parameter is a timestamp. You can see it's strangely alike what you'd get in the console with

Date.now()

This is done to ensure the URL changes and avoid receiving a cached version of the page.

It's described in the documentation :

cache (default: true, false for dataType 'script' and 'jsonp')

Type: Boolean If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.

like image 86
Denys Séguret Avatar answered Oct 22 '22 16:10

Denys Séguret