asp.net mvc 2 – MicrosoftMvcAjax.js throws javascript error when updating table elements in IE8


In IE8 or anything older, innerHTML is not supported on certain elements like TR & TD. Unfortunately, the MicrosoftMvcAjax.js file included in the MVC 2 project uses innerHTML for the Ajax update method within the Ajax.BeginForm or Ajax.ActionLink.

To fix that, look into Line 18 of MicrosoftMvcAjax.js and replaced it with this:

Sys.Mvc.MvcHelpers.updateDomElement = function (target, insertionMode, content) { if (target) { switch (insertionMode) { case 0: $(target).html(content); break; case 1: if (content && content.length > 0) { $(target).html(content + target.innerHTML.trimStart()); } break; case 2: if (content && content.length > 0) { $(target).html(target.innerHTML.trimEnd() + content); } break; } } }

solution 2:

If problem still exists after applying this above patch, use below :
– Use ” MicrosoftMvcAjax.debug.js ” instead of  ” MicrosoftMvcAjax.js ”
– Open MicrosoftMvcAjax.debug.js & goto line 349 & modify as below :

switch (insertionMode) {            case Sys.Mvc.InsertionMode.replace:                $(target).html(”);                $(target).html(content);                 break;            case Sys.Mvc.InsertionMode.insertBefore:                if (content && content.length > 0) {                    $(target).html(content + target.innerHTML.trimStart());                }                break;            case Sys.Mvc.InsertionMode.insertAfter:                if (content && content.length > 0) {                    $(target).html(target.innerHTML.trimEnd() + content);                }                break;        }

 

(I apologize for improper alignment, it just wordpress editor … 😦

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s