Bug Tracker

Opened 10 years ago

Closed 9 years ago

#5097 closed bug (worksforme)

getJSON break FF history

Reported by: monstroplante Owned by:
Priority: low Milestone:
Component: ajax Version: 1.4.3
Keywords: Cc:
Blocked by: Blocking:

Description

If i redirect on the callback of getJSON and then use the back button on the browser, the displayed page is not the exepted one. (tested on FF3.5).

Here is a test code :

<a class="btTest">Test</a> <script type="text/javascript"> $('.btTest').click(function() { $.getJSON('http://maps.google.com/maps/geo?callback=?', function() { window.location = 'http://google.fr'; }); }); </script>

I found a hack :

Handle JSONP-style loading window[ jsonp ] = function(tmp){setTimeout(function() {

data = tmp; success(); complete(); Garbage collect window[ jsonp ] = undefined; try{ delete window[ jsonp ]; } catch(e){} if ( head )

head.removeChild( script );

}, 1);};

Change History (6)

comment:1 Changed 9 years ago by dmethvin

Component: unfiledajax

comment:2 Changed 9 years ago by addyosmani

#5044 is a duplicate of this ticket.

comment:3 Changed 9 years ago by Rick Waldron

Milestone: 1.4
Priority: majorlow
Status: newopen
Version: 1.3.21.4.3

Confirmed.

http://jsbin.com/uboce

(wont work correctly on jsfiddle)

comment:4 Changed 9 years ago by Rick Waldron

Milestone: 1.5

comment:5 Changed 9 years ago by snover

Milestone: 1.5

When a script loads and immediately redirects the page, Firefox pretends that it like the server performed a 3xx direct and removes the previous page from the browser history. This has nothing to do with jQuery.

broken works, using onload works, using setTimeout

This does not happen if the assignment to window.location happens from the script’s onload method, or if it is deferred using setTimeout.

Workaround: Do not modify the location of the window using window.location in response to a JSONP call without wrapping it in setTimeout.

comment:6 Changed 9 years ago by dmethvin

Resolution: worksforme
Status: openclosed
Note: See TracTickets for help on using tickets.