AppendChild在Ajax请求中不起作用
AppendChild not working in Ajax request
我有一个脚本,当当前字段被按下时添加一个输入字段元素。当我使用innerHTML时,它取代了当前,这不是我想要的。所以我认为appendChild应该添加而不是替换,但它不工作。这是我的脚本。
<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文件。
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不能。谢谢。
parent.appendChild()是一个等待DomNode对象的函数,你正在传递一个字符串,它不能工作…
试题:
var d = document.createElement('div');
d.innerHtml = xmlhttp.responseText;
document.getElementById("org_div1").appendChild(d);
AppendChild需要一个对象,而innerHTML需要一个String。由于您的服务器返回部分HTML,因此这只适用于innerHTML。
相关文章:
- 为什么 AJAX POST 请求不起作用
- AJAX请求不起作用,除非使用alert()
- Ajax Post请求不起作用
- IE8 jquery ajax头请求不起作用
- jQuery点击功能在获取请求后不起作用
- 使用Javascript的Ajax请求在iPhone浏览器中不起作用
- JQuery AJAX请求不起作用
- Node.js cors请求-异步示例不起作用
- Ajax 对 JSON 的请求不起作用
- React JS js 中的 AJAX 请求不起作用
- 对 URL 的 JSON-P 请求不起作用
- Jquery ajax请求不起作用
- 带有ajax xml请求的Node js脚本不起作用
- Ajax请求三次都不起作用,然后就起作用了
- AngularJS http.jsonp请求.then和.success函数不起作用
- Jquery ajax发布请求不起作用
- 外部AJAX请求不起作用
- 对SOAP服务的Preflight OPTIONS请求不起作用
- 使用AJAX发出POST请求;不起作用
- 第二个ajax请求在移动浏览器上不起作用