在下拉框中显示"正在加载..."

Ton*_*orf 6 ajax asp.net-mvc jquery

我正在运行数据库查询以使用jquery加载下拉框.有没有办法在查询运行时在下拉框中显示"正在加载..."字样?

谢谢.

alg*_*cas 11

您可以在ajax运行时将临时项添加到下拉列表中:

$('#myDropDown').prepend($('<option></option>').html('Loading...'));
Run Code Online (Sandbox Code Playgroud)


Sol*_*ogi 8

我们打电话给你的'userChoice',你可以写代码

$(document).ready(
    function()
    {

        //Before calling your ajax method, clear the select drop down.
        //and add a loading option.
        $('#userChoice')
            .children()
            .remove()
            .end()
            .append('<option value="">Loading...</option>');

        $.ajax(

                    //Load the userChoice as usual in success handler of your ajax call. 
                    success : function() { //Load #userChoice } 
              );


    }
);
Run Code Online (Sandbox Code Playgroud)