IE shows run time error for innerHTML

后端 未结 9 2108
谎友^
谎友^ 2020-12-11 09:54

I have a jsp page in which rows are created dynamically to a table using java script. It is working fine in all the browsers except IE. In IE it is showing the error Unknown

9条回答
  •  孤街浪徒
    2020-12-11 10:26

    My problem was it worked in firefox and did not work in IE know am using multipe tables and forms inside each other ...

    General solution

    Use JQuery it can solve such issues between browsers in my case i faced this error and replaced with the $('#'+loc).html(ddl) line instead of innerHTML and it worked

    function buildDDL(){
        if (http_request.readyState == 4)
        {
            var ddl = http_request.responseText;
            ddl = ddl.replace(/[\n]/g, '');
            if(ddl != 'SESSION_EXPIRED'){
                $('#'+loc).html(ddl);
                //document.getElementById(loc).innerHTML = ddl;
            }else{
                location.href = 'errorPage.jsp?status='+ddl;
            }
            http_request = false;
        }
    }
    

    If you're wondering about functionality, then jQuery's html() performs the same intended functionality as innerHTML, but it also performs checks for cross-browser compatibility.

    For this reason, always use jQuery's html() instead of innerHTML where possible.

提交回复
热议问题