jQuery: The Write Less, Do More JavaScript Library

Ticket #2816 (closed bug: fixed)

Opened 3 months ago

Last modified 2 months ago

erroneous behavior with IE when re-ajaxifying links in an ajax-loaded div

Reported by: lamyseba Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.2.4 Component: ajax
Version: 1.2.3 Keywords: ajax, IE, absolute url, second time replace
Cc: Needs: Review

Description

I used the Jquery ajax content plugin ( http://www.andreacfm.com/index.cfm/jquery-plugins ), wich itself use the ajax behaviour of jquery.

I use ajax to replace a whole div. As there are some ajax links inside the div, I re-ajaxify them after the div is replaced, using ajaxContent.

This works fine with Firefox, Safari, Konqueror, but in IE 6-7 I got a strange behaviour: the first "ajaxification" of the link works well,but the re-ajaxification does not work well.

Investigating, I realized that IE interprets all the urls coming back from an ajax call, and includes the host into them. i.e : "/my/relative/url.html" will become: "http://myhost.com/my/relative/url.html".

This cause jQuery to interpret the second ajax call differently. In jQuery-1.2.3.js, at line 2631, there is a test:

// If we're requesting a remote document and trying to load JSON //or Script with a GET
if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && s.dataType == "script" && s.type.toLowerCase() == "get" ) {

This test will not be passed the first time, and it will be passed the second Time in IE only, causing this strange behaviour. - The solution I adopted is to always remove the host before doing the call. - A better solution would be to modify jquery so that it checks wether the host is the same as the one in the url we're coming from, rather than just check if url contains (http) or (//). This will make IE behave the same in the first and second ajax call

Anyway, what caused the strange behaviour was the fact that the "X- Requested-With" header wasn't set if the test was passed. And I needed this header for my application to work correctly (I'm using Ruby on Rails). So, maybe a good idea would be to add this header in all case, may this test be passed or not.

Regards

Sebastien.

Attachments

remote-ajax.diff (0.7 kB) - added by flesler 2 months ago.
This should fix the former naive check ( shouldn't '//' be '/' ? )

Change History

Changed 2 months ago by flesler

This should fix the former naive check ( shouldn't '//' be '/' ? )

Changed 2 months ago by davidserduke

The reason that check is in there is for #1750 but perhaps there is another check needed too?

Changed 2 months ago by flesler

  • status changed from new to closed
  • resolution set to fixed

Closed at [5586].

Note: See TracTickets for help on using tickets.