无法从javascript函数中填充下拉列表

无法从javascript函数中填充下拉列表,javascript,jquery,asp.net,ajax,Javascript,Jquery,Asp.net,Ajax,我使用 ScriptManager.RegisterStartupScript(this, this.GetType(), "pop", "<script>alert('File Size Can Not Exceed 400Kb Limit.');window.onload = function () {RetainValues(); }</script>", false); RetainValues()函数一完成,下拉列表就会被填充。因为它不在RetainValue

我使用

ScriptManager.RegisterStartupScript(this, this.GetType(), "pop", "<script>alert('File Size Can Not Exceed 400Kb Limit.');window.onload = function () {RetainValues(); }</script>", false);

RetainValues()函数一完成,下拉列表就会被填充。因为它不在RetainValues()的范围内填充,所以我无法设置它的值

首先,由于您正在调用包含Ajax调用的
GetDropDownData
,因此它是异步的。这意味着您无法判断ajax调用何时完成。可能是1秒或1分钟!但是,javascript会立即尝试查找在ajax调用有机会完成之前返回的选项的长度


只有在ajax调用完成后,才能确定这些选项是否确实已填充。这可以在ajax调用的
success
函数中完成,也可以将回调函数传递给要调用的
success
函数,该函数在ajax调用返回的基础上执行您需要执行的任何操作。

首先,因为您正在调用包含ajax调用的
GetDropDownData
,它是异步的。这意味着您无法判断ajax调用何时完成。可能是1秒或1分钟!但是,javascript会立即尝试查找在ajax调用有机会完成之前返回的选项的长度

RetainValues(){
GetDropDownData(); 
}
   function GetDropDownData(){
   $.ajax({ url: "URL to call", 
       success: function(data){
            //fill the dropdown
             $(field).find("option").length;
            // U will get the exact length. Now u can do whatever u want using the Length.
        }
    });
}

只有在ajax调用完成后,才能确定这些选项是否确实已填充。这可以在ajax调用的
success
函数中完成,也可以将回调函数传递给要调用的
success
函数,该函数在ajax调用返回的基础上执行您需要执行的任何操作。

首先,因为您正在调用包含ajax调用的
GetDropDownData
,它是异步的。这意味着您无法判断ajax调用何时完成。可能是1秒或1分钟!但是,javascript会立即尝试查找在ajax调用有机会完成之前返回的选项的长度

RetainValues(){
GetDropDownData(); 
}
   function GetDropDownData(){
   $.ajax({ url: "URL to call", 
       success: function(data){
            //fill the dropdown
             $(field).find("option").length;
            // U will get the exact length. Now u can do whatever u want using the Length.
        }
    });
}

只有在ajax调用完成后,才能确定这些选项是否确实已填充。这可以在ajax调用的
success
函数中完成,也可以将回调函数传递给要调用的
success
函数,该函数在ajax调用返回的基础上执行您需要执行的任何操作。

首先,因为您正在调用包含ajax调用的
GetDropDownData
,它是异步的。这意味着您无法判断ajax调用何时完成。可能是1秒或1分钟!但是,javascript会立即尝试查找在ajax调用有机会完成之前返回的选项的长度

RetainValues(){
GetDropDownData(); 
}
   function GetDropDownData(){
   $.ajax({ url: "URL to call", 
       success: function(data){
            //fill the dropdown
             $(field).find("option").length;
            // U will get the exact length. Now u can do whatever u want using the Length.
        }
    });
}
只有在ajax调用完成后,才能确定这些选项是否确实已填充。这可以在ajax调用的
success
函数中完成,也可以将回调函数传递给要调用的
success
函数,该函数根据ajax调用的返回执行您需要执行的任何操作

RetainValues(){
GetDropDownData(); 
}
   function GetDropDownData(){
   $.ajax({ url: "URL to call", 
       success: function(data){
            //fill the dropdown
             $(field).find("option").length;
            // U will get the exact length. Now u can do whatever u want using the Length.
        }
    });
}