Ticket #8764 (closed bug: wontfix)
Regression in getJSON
| Reported by: | patrick.wolf@… | Owned by: | jaubourg |
|---|---|---|---|
| Priority: | high | Milestone: | 1.next |
| Component: | ajax | Version: | 1.5.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Using $.getJSON for a JSONP request always adds a parameter &_=somenumber to the URL which can break the request, because not all server system do expect a parameter called _ in the request.
Using the example from http://api.jquery.com/jQuery.getJSON/ demonstrates the problem when using jQuery 1.5.2 and viewing the request using FF and Live HTTP Header. Running the same example in 1.4.4 doesn't add that parameter.
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
{
tags: "cat",
tagmode: "any",
format: "json"
},
function(data) {
alert('test');
});
Change History
comment:1 Changed 2 years ago by rwaldron
- Owner set to jaubourg
- Priority changed from undecided to high
- Status changed from new to assigned
- Component changed from unfiled to ajax
comment:2 Changed 2 years ago by jaubourg
- Status changed from assigned to closed
- Resolution set to wontfix
It's because default for cache option is false in the context of a script request (which jsonp is). You have several solutions around this:
- use ajax
$.ajax( "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?", { dataType: "jsonp", cache: true, data: { tags: "cat", tagmode: "any", format: "json" }, success: function(data) { alert('test'); } } ); - set cache option to true by default using ajaxSetup:
$.ajaxSetup({ cache: true; }); - make sure cache option is true by default for script using a prefilter
$.ajaxPrefilter( "script", function( options, originalOptions ) { if ( originalOptions.cache == null ) { options.cache = true; } } ); - create a prefilter to deal with the service that poses a problem:
$.ajaxPrefilter( "script", function( options ) { if ( /^http:\/\/api\.flickr\.com\//.test( options.url ) ) { options.cache = true; } } );
Lots of alternatives here.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
