使用appendChild不工作在Ajax请求 [英] AppendChild not working in Ajax request

查看:108
本文介绍了使用appendChild不工作在Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本来添加一个输入域元素时,当前是​​pssed $ P $。当我使用的innerHTML它替换当前的,这不是我想要的。所以我想的appendChild应该补充而不是取代,但它不工作。这是我的脚本。

I have a script to add an input field element when a current one is pressed. When i use innerHTML it replaces the current, which is not what i want. So I figured appendChild should add and not replace, but its not working. Heres my script..

<script type="text/javascript">
function addfile()
{
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("org_div1").appendChild = xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","addfile.php");
xmlhttp.send();
}
</script>

和我的HTML内容。

<div id="org_div1" class="file_wrapper_input">

                        <input type="hidden" value="1" id="theValue" />
<input type="file" class="fileupload" name="file1" size=
"80" onchange="addfile()" /></div>

和我addfile.php文件。

And my addfile.php file..

    var i=0;
        var ni = document.getElementById('org_div1');
        var numi = document.getElementById('theValue');
        var num = (document.getElementById('theValue').value -1)+ 2;
        numi.value = num;
        var divIdName = num;
</script>
<input type="file"  class="fileupload" size="80" name="file' + (num) + '" onchange="addfile()" />;

任何输入?此外,innerHTML的不工作,使用appendChild没有。谢谢你。

Any input? Again, innerHTML DOES work, appendChild does not. Thanks.

推荐答案

parent.appendChild()正在等待れ对象的函数,你传递一个字符串,它不能正常工作......

parent.appendChild() is a function waiting for DomNode Object and you are passing a String, it can't work...

尝试:

var d = document.createElement('div');
d.innerHtml = xmlhttp.responseText;
document.getElementById("org_div1").appendChild(d);

这篇关于使用appendChild不工作在Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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