最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SCRIPT 600 Error : Invalid target element for this operation - Stack Overflow

programmeradmin4浏览0评论

I have a php site that works fine in FireFox and Chrome, but breaks pletly in IE.

Here is just one of the scripts that is throwing an error... SCRIPT600: Invalid target element for this operation.

function loadDeals() {
    $.get("modules/remendations/viewremendations.php",{},function(response){
        document.getElementById("dealdata").innerHTML = response;
    });
}

It throws the error on the line that sets the innerHTML...Any ideas why this is happening?

I have a php site that works fine in FireFox and Chrome, but breaks pletly in IE.

Here is just one of the scripts that is throwing an error... SCRIPT600: Invalid target element for this operation.

function loadDeals() {
    $.get("modules/remendations/viewremendations.php",{},function(response){
        document.getElementById("dealdata").innerHTML = response;
    });
}

It throws the error on the line that sets the innerHTML...Any ideas why this is happening?

Share Improve this question asked Aug 24, 2011 at 17:57 Carl WeisCarl Weis 7,06215 gold badges65 silver badges86 bronze badges 2
  • 2 What is the element with id dealdata? – Paul Commented Aug 24, 2011 at 17:59
  • 3 If you already use jQuery, then why not for that too? $('#dealdata').html(response). – Felix Kling Commented Aug 24, 2011 at 18:00
Add a ment  | 

2 Answers 2

Reset to default 13

IE has a problem replacing TBODY contents with innerHTML. The jQuery given above works; if you are not using jQuery, another solution is to have a <div id='helper' style='visibility:hidden'/> somewhere in the page - when the response arrives, put the value with a surrounding <table> tag into the hidden div, then use the DOM to remove the old contents from your visible tag and insert the elements from the hidden tag 1 by 1:

var a=document.getElementById("dealdata");

while(a.firstChild!=null)
  a.removeChild(a.firstChild);

var b=document.getElementById("helper");
b.innerHTML="<table>"+this.responseText+"</table>";
while(b.tagName!="TR") {
  if(b.tagName==null)
    b=b.nextSibling;
  else
    b=b.firstChild;
}
for(;b!=null;b=b.nextSibling)
  a.appendChild(b);

Try this: are you using jquery?

also looks like you have an extra set of brackets in there (i think between ,{},)

function loadDeals() {
    $.get("modules/remendations/viewremendations.php",function(response){
        $("#dealdata").html(response);
    });
}
发布评论

评论列表(0)

  1. 暂无评论