Bug Tracker

Opened 12 years ago

Closed 12 years ago

#2816 closed bug (fixed)

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

Reported by: lamyseba Owned by:
Priority: major Milestone: 1.2.4
Component: ajax Version: 1.2.3
Keywords: ajax, IE, absolute url, second time replace Cc:
Blocked by: Blocking:

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 (1)

remote-ajax.diff (678 bytes) - added by flesler 12 years ago.
This should fix the former naive check ( shouldn't '' be '/' ? )

Download all attachments as: .zip

Change History (3)

Changed 12 years ago by flesler

Attachment: remote-ajax.diff added

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

comment:1 Changed 12 years ago by davidserduke

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

comment:2 Changed 12 years ago by flesler

Resolution: fixed
Status: newclosed

Closed at [5586].

Note: See TracTickets for help on using tickets.