Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在asp.NETC中使用ajax和web服务使用数据库中的数据填充动态创建的dropdownlist# var指数=0; 函数newitem(){ 索引++; var objTo=document.getElementById('newitem') var divtest=document.createElement(“div”); setAttribute(“类”、“窗体组removeclass”+索引); var rdiv='removeclass'+索引; divtest.innerHTML= --选择-- '; 目标追加儿童(divtest); }; 函数删除\u创建的\u项(idOfCreatedItem){ $('.removeclass'+idOfCreatedItem.remove(); }_Javascript_C#_Asp.net Ajax - Fatal编程技术网

Javascript 如何在asp.NETC中使用ajax和web服务使用数据库中的数据填充动态创建的dropdownlist# var指数=0; 函数newitem(){ 索引++; var objTo=document.getElementById('newitem') var divtest=document.createElement(“div”); setAttribute(“类”、“窗体组removeclass”+索引); var rdiv='removeclass'+索引; divtest.innerHTML= --选择-- '; 目标追加儿童(divtest); }; 函数删除\u创建的\u项(idOfCreatedItem){ $('.removeclass'+idOfCreatedItem.remove(); }

Javascript 如何在asp.NETC中使用ajax和web服务使用数据库中的数据填充动态创建的dropdownlist# var指数=0; 函数newitem(){ 索引++; var objTo=document.getElementById('newitem') var divtest=document.createElement(“div”); setAttribute(“类”、“窗体组removeclass”+索引); var rdiv='removeclass'+索引; divtest.innerHTML= --选择-- '; 目标追加儿童(divtest); }; 函数删除\u创建的\u项(idOfCreatedItem){ $('.removeclass'+idOfCreatedItem.remove(); },javascript,c#,asp.net-ajax,Javascript,C#,Asp.net Ajax,这很乱,但我想我明白你在做什么 在objTo.appendChild(divtest)之后在页面中插入选择下拉列表,对API执行Ajax调用: var index = 0; function newitem() { index++; var objTo = document.getElementById('newitem') var divtest = document.createElement("div"); divtest.setAttribute("cl

这很乱,但我想我明白你在做什么

objTo.appendChild(divtest)之后
在页面中插入
选择
下拉列表,对API执行Ajax调用:

var index = 0;
function newitem() {

    index++;
    var objTo = document.getElementById('newitem')
    var divtest = document.createElement("div");
    divtest.setAttribute("class", "form-group removeclass" + index);
    var rdiv = 'removeclass' + index;
    divtest.innerHTML = '<div class="col-sm-3 nopadding"><div class="form-group">
<select class="form-control" id="ddlitem' + index + '"name="ddlitem"><option
value="">--select--</select> </div></div><div class="col-sm-3
nopadding"><div class="form-group"> <input type="text"
class="form-control" id="txtquantity' + index + '" 
name="txtquantity" value=""></div></div><div class="col-sm-3
nopadding"><div class="form-group"> <input type="text"
class="form-control" id="txtprice' + index + ' "name="txtprice"
disabled="disabled" value="" ></div></div><div class="col-sm-3
nopadding"><div class="form-group"><div class="input-group"> <input
type="text" class="form-control" id="txttotal' + index + '"
name="txttotal" disabled="disabled" value="" ><div
class="input-group-btn"> <button class="btn btn-danger"
type="button" onclick="remove_created_item(' + index + ');"> <span
class="glyphicon glyphicon-minus" aria-hidden="true"></span>
</button></div></div></div></div><div class="clear"></div>';
    objTo.appendChild(divtest);
};

function remove_created_item(idOfCreatedItem) {
    $('.removeclass' + idOfCreatedItem).remove();
}
var copyofinex=索引;
$.get(“/api/whatever”,函数(数据){
$(“#ddlitem”+copyOfIndex).html(data);//data=>可以是包含所有
警报(“已执行加载”);
});
上面不确定您的代码是如何初始化的,但您应该使用索引的副本(
copyofinex
此处),以确保ajax调用完成时,
index
不会使用过时的值


另外,在通过
objTo.appendChild(divtest)将元素插入DOM之前,似乎需要关闭

首先清除你的问题详细阐述你的问题,使用正文添加细节,而不是把所有内容都塞进主题中,只留下正文中的代码。这毫无意义。
var copyOfIndex = index;
$.get( "/api/whatever", function( data ) {
 $( "#ddlitem" + copyOfIndex ).html( data ); // data => can be the html containing all the <options> 
 alert( "Load was performed." );
});