Nik
Nik

Reputation: 7283

How to get rid of the underscore query parameter that jQuery adds to AJAX requests?

I am using jQuery and running this Javascript:

$.ajax ({
    url: 'http://1.1.1.1/cgi-bin/script.cgi?scm:scm/data/system_names',
    context: $("#elem"),
    crossDomain: true,
    dataType: "xml",
    success: function (data) {
        $xmlDoc = parseXML (data);
        $(this).html ($xmlDoc.find ("elem").text ());
    }
});

When the requests runs, I can see that this URL is requested:

http://1.1.1.1/cgi-bin/script.cgi?scm:scm/data/system_names&_=1306868212809

How can I get rid of the &_=1306868212809 part? It's messing with my request. I have no control over the CGI script, so I have to do it the way you see.

Upvotes: 2

Views: 299

Answers (3)

Matthew Nessworthy
Matthew Nessworthy

Reputation: 1428

You need to set the cache key to true

$.ajax ({
  url: 'http://1.1.1.1/cgi-bin/script.cgi?scm:scm/data/system_names',
  context: $("#elem"),
  crossDomain: true,
  dataType: "xml",
  cache: true,
  success: function (data) {
    $xmlDoc = parseXML (data);
    $(this).html ($xmlDoc.find ("elem").text ());
  }
});

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

Try setting the cache parameter:

cache: true

Upvotes: 3

slandau
slandau

Reputation: 24102

Shouldn't you be wrapping the URL in string quotes?

$.ajax ({
    url: 'http://1.1.1.1/cgi-bin/script.cgi?scm:scm/data/system_names',
    context: $("#elem"),
    crossDomain: true,
    dataType: "xml",
    success: function (data) {
        $xmlDoc = parseXML (data);
        $(this).html ($xmlDoc.find ("elem").text ());
    }
});

From their documentation - http://api.jquery.com/jQuery.ajax/

The Url property should be a string.

Upvotes: 0

Related Questions