Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#3 | 919994-replace-command-improvement.patch | 965 bytes | merlinofchaos |
#1 | 919994-replace-command-improvement.patch | 1.39 KB | merlinofchaos |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedNote: 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.
Comment #2
quicksketchWhat 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.
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedQuicksketch's suggestion appears to work for me. Let's try this patch.
Comment #5
rfaysubscribe
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedhttp://drupal.org/node/736066#comment-3493052