代码之家  ›  专栏  ›  技术社区  ›  Zo Has

通过AJAX提交表单,加载进度如何?

  •  0
  • Zo Has  · 技术社区  · 14 年前

    4 回复  |  直到 14 年前
        1
  •  1
  •   RPM1984    14 年前

    我想知道 推荐的方法

    好吧,这取决于你在做什么,你在更新表单的哪些部分,表单有多大,你要向服务器发送什么值。

    一般来说,如果您想更新一些简单的东西(dropdownlist、listbox等),您通常会使用JavaScript(或jQuery)来调用支持AJAX的web服务。这样,您只需向服务器发送它所需的数据,ViewState/Cookie之类的内容不会通过网络发送。您还可以完全控制执行前/执行后事件(因此可以添加加载图像,调用WS,然后清除它们)。

    使用以下代码可以轻松创建进度图像:

    <ProgressTemplate>
       <img src="someloadingimage.gif" alt="Loading" />
    </ProgressTemplate>
    

    HTH公司

        2
  •  3
  •   Ozzz    14 年前

    1-准备一个客户端div显示:无“样式属性。把你的加载图像放进去。

    3-在响应中添加某种“informationreceived”符号,并从客户端检查此响应,然后将divs display属性改回“none”

        3
  •  1
  •   Alpesh    14 年前

    如果使用jqueryforajax请求,那么可以使用以下事件-

    $.ajax({ url: "test.html",
     type: "GET",
     beforeSend: function(){
                 -----load your loader here-----
                 });,
     success: function(){
          ------remove your loader here -----------  
          Remaining code
          }});
    

    也可以使用POST。在上面的例子中,我使用了GET。

    有关详细文档,请参阅- http://api.jquery.com/jQuery.ajax/

        4
  •  1
  •   RobertPitt    14 年前

    像这样为你的加载程序创建一个小插件。

    $.fn.ShowLoader = function(on){
        switch(on)
        {
            case true:
                $(this).show();
            break;
            default:
                $(this).hide();
            break;
        }
    }
    

    然后使用以下命令:

    $('form').submit(function(){
        var Form = $(this);
    
        $('.loader',Form).ShowLoader(true);
    
        //Gather some params
        Location = Form.attr('src');
        Data = Form.Serialize();
    
        $.post(Location,Data,function(result){
            result = result || false;
            if(result)
            {
                 $('.loader',Form).ShowLoader(false); //Disable the loader
                 //Process result
            }
        });
    })
    

    loader