Scenario: I am using AJAX to add, remove and update items in a table. To do this, I am using the 'replace' and 'append' commands using TR tags.

However, ajax.js contains this code:

     // Manually insert HTML into the jQuery object, using $() directly crashes
     // Safari with long string lengths. http://dev.jquery.com/ticket/3178
    var new_content = $('<div></div>').html(response.data);

That is great except that it basically forces what I'm adding into a div. That's not so hot when I'm trying to deal with TRs. I checked the problem and I think we can alleviate this somewhat with length checking, where we check to see if the string is longer than Safari's length and if it is, fall back to the less optimal version but otherwise stay with the classic var content = $(html) version.

Patch to follow.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

Status: Active » Needs review
FileSize
1.39 KB

Note: This patch is necessary for CTools unless we want CTools (and other modules that want to manipulate non-DIV tags) to implement their own AJAX commands to do this, which is less than fun.

quicksketch’s picture

What about something more universal like wrapping in a DIV, using $.html(), then removing the parent DIV? I'm not sure how the DOM would like that for elements like a TR. But then again, I don't think a TR really works that well when created directly as a jQuery object either. As noted on the linked to above (http://dev.jquery.com/ticket/3178), using $() on a really long string probably isn't a great idea anyway considering it requires doing a regex on it.

     // Manually insert HTML into the jQuery object, using $() directly crashes
     // Safari with long string lengths. http://dev.jquery.com/ticket/3178
    var new_content = $('<div></div>').html(response.data).contents();
merlinofchaos’s picture

Quicksketch's suggestion appears to work for me. Let's try this patch.

rfay’s picture

subscribe

merlinofchaos’s picture

Status: Needs review » Closed (duplicate)