Possible bug introduced ajax load() in 1.2.2 (using Rails and Safari)

Possible bug introduced ajax load() in 1.2.2 (using Rails and Safari)

Hi all,<div>
</div><div>We've come across a problem using load() for ajax requests using Rails and Safari (3.1.1). This problem only exists in jQuery versions 1.2.2 and newer.</div><div>
</div><div>I think it may have something to do with this changeset incorporated into the 1.2.2 release:</div><div>
</div><div><a href="http://dev.jquery.com/changeset/4155" target="_blank">http://dev.jquery.com/changeset/4155</a></div>
<div>
</div><div>After this change, the load() function forces a dataType of "html" when making the ajax request.</div><div>
</div><div>In Firefox (any version before 3.0 RC1, but that is another story), we can still use load() to replace the content of the div as expected. The xhr request goes to rails, and partial page content is returned and inserted into the page div.</div>
<div>
</div><div>What happens in Safari is that the content for the entire page, including the layout, is returned from the xhr request (as if it were a normal full page load) and inserted into the div, putting duplicate page headers and menus, etc. into the page.</div>
<div>
</div><div>I took the 1.2.5 version of jquery.js, and removed the dataType: "html" parameter from the ajax call made inside the load() function (line 2450 in the uncompressed version), and then the ajax request works again as expected.</div>
<div>
</div><div>Do you know if there is any way we can fix this without breaking the bug that this changeset fixed in the first place?</div><div>
</div><div>For background, here is the .js file we're using:</div>
<div>
</div><div><div>$(document).ready(function() {</div><div><span style="white-space:pre"> </span>// AJAX paginatation - <a href="http://ozmm.org/posts/ajax_will_paginate_jq_style.html" target="_blank">http://ozmm.org/posts/ajax_will_paginate_jq_style.html</a></div>
<div><span style="white-space:pre"> </span>$('.pagination a').livequery('click', function() {</div><div><span style="white-space:pre"> </span>  $('#live_table').fadeOut('fast').load(this.href).fadeIn('fast');</div>
<div><span style="white-space:pre"> </span>  return false;</div><div><span style="white-space:pre"> </span>});</div><div>});</div><div>
</div><div>// Rails responds_to fix - <a href="http://ozmm.org/posts/jquery_and_respond_to.html" target="_blank">http://ozmm.org/posts/jquery_and_respond_to.html</a></div>
<div>jQuery.ajaxSetup({ </div><div>  'beforeSend': function(xhr) {</div><div>    xhr.setRequestHeader("Accept", "text/javascript");</div><div>  } </div><div>});</div><div>
</div><div>And the request is being made to a Rails controller that does the following:</div>
<div>
</div><div><div>  def index</div><div>    @line_items = LineItem.paginate(:all, :order => 'id DESC', :page => params[:page])</div><div>
</div><div>    respond_to do |format|</div><div>      format.html # index.haml</div>
<div>      format.js   { render :partial => 'table' }</div><div>      format.xml  { render :xml => @line_items }</div><div>    end</div><div>  end</div><div>
</div><div>
</div><div>Thanks for you help everyone,</div>
<div>
</div><div> - Tim</div></div></div>




























    • Topic Participants

    • tim