Reputation: 13
I am trying to load JSON encoded data from a remote site using jQuery, however when jQuery tries to call this URL it appends the correct function to callback=? so it's something like callback=jsonp1256856769 but it also adds _=1256856769 to the url. So the url ends up being something like http://www.example.com/link/to/file.php?format=json&lang=en&callback=jsonp1256856769&_=1256856769
Now the problem is that that file that I am using that calls it can't interpret the _=1234234 and I can't change it so I have to fix the jQuery problems
How can I get jQuery to not appened that _= to the URL that it calls
function getData(){
url = "http://www.example.com/link/to/file.php";
url += "?format=json&lang=en";
$.getJSON(url+"&callback=?",function(data){formatData(data);});
}
*Above is the snippet of JavaScript that I am currently using
*Note the domain I am using is not example.com
Upvotes: 1
Views: 1106
Reputation: 15552
UPDATE: added code
The _=
part is there, because JSONP request are cache: false
by default. You can set cache: true
, which will make the _=
part go away, but the browser will cache the requests.
function getData() {
url = "http://www.example.com/link/to/file.php";
url += "?format=json&lang=en";
$.ajax({
'url': url,
'type': 'GET',
'dataType': 'jsonp', // this adds &callback=? by design
'cache': true,
'success': function(data) { formatData(data); }
});
}
Upvotes: 3