IE操作的IE问题 [英] IE issue with DOM manipulation

查看:79
本文介绍了IE操作的IE问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  document.getElementById(output)我有一个AJAX表单,我使用这一行接收到一个响应: .innerHTML = xmlhttp.responseText; 

输出是一个div,在IE中我收到一个未知的JavaScript错误。



是否是从AJAX传出的内容是导致此错误的,或者在该行出现了某些语法错误?



编辑:

  if(valid == true){
// AJAX
if(window.XMLHttpRequest )
{// IE7 +,Firefox,Chrome,Opera,Safari的代码
xmlhttp = new XMLHttpRequest();
} else {// IE6,IE5的代码
xmlhttp = new ActiveXObject(Microsoft.XMLHTTP);
}

xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4&& xmlhttp.status == 200)
{
document.getElementById(output)。innerHTML = xmlhttp.responseText;
id = document.getElementById(parentID)。
}
}
var parameters =shedloadofvariables+ shedloadofVariables;

xmlhttp.open(POST,register.php,true);
xmlhttp.setRequestHeader(Content-type,application / x-www-form-urlencoded);
xmlhttp.send(parameters);
}
else {
alert(请填写所有字段);
}

干杯

解决方案

我仍然不能完全理解问题(Andy E的答案肯定有帮助)。



我找到了一个解决方案这个问题:

  var t = document.createElement('div'); 
t.innerHTML = xmlhttp.responseText;
document.getElementById(output)。appendChild(t);

无瑕疵。



不知道为什么,但我不会质疑它,因为它有效!


I have a AJAX form and I use this line on receiving a response:

document.getElementById("output").innerHTML = xmlhttp.responseText;

Output is a div and in IE I'm getting an Unknown JavaScript Error.

Would it be the content that's being passed from the AJAX that's causing this error or is there something syntactically wrong with that line?

EDIT:

if(valid==true){
  //AJAX
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
  }else{// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  xmlhttp.onreadystatechange=function()
  {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
          document.getElementById("output").innerHTML = xmlhttp.responseText;
          id = document.getElementById("parentID").value;
      }
  }
  var parameters = "shedloadofvariables"+shedloadofVariables;

  xmlhttp.open("POST", "register.php", true);
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.send(parameters);
  }
else{
  alert("Please Fill in All Fields");   
}

Cheers

解决方案

I still don't understand the problem fully (Andy E's answer certainly helps though).

I found a work-around for this issue:

var t = document.createElement('div');
t.innerHTML = xmlhttp.responseText;
document.getElementById("output").appendChild(t);

Flawless.

Don't know why, but I'm not about to question it, because it works!

这篇关于IE操作的IE问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆