How to show the ajax loader image while remote val

2019-08-05 16:26发布

in my asp.net mvc3 application i am doing remote validation if a user already exist using data annotation . it is working perfectly . i was wondering if there is any why i can show the ajax loader image beside the input field in the form while remote validation(ajax request) is taking place.

please help me

Thanks

3条回答
▲ chillily
2楼-- · 2019-08-05 16:49

If that was me, I would want to stop user from entering data into any other fields until this is validated, therefore I would use AjaxOptions to specify animation and duration of that animation.

I'd have something on the lines of:

@{
    AjaxOptions ajaxOpts = new AjaxOptions
    {
        UpdateTargetId = "updateDiv",
        LoadingElementId = "myImg",
        LoadingElementDuration = 2000,        
        HttpMethod = "GET"        
    };    
}
查看更多
神经病院院长
3楼-- · 2019-08-05 17:05

I don't think you can do it without writing the validation code yourself.

See this article: http://www.highoncoding.com/Articles/767_Remote_Validation_in_ASP_NET_MVC_3.aspx

Within the AJAX call you would have to add a beforeSend to display the image, then hide it on complete.

查看更多
我想做一个坏孩纸
4楼-- · 2019-08-05 17:14

You can use $.ajaxStart .ajaxStop for this purpose:

$("#yourRegisterFormToValidate")
          .ajaxStart(function () { $(".loader").show(); })
          .ajaxStop (function () { $(".loader").hide(); });
查看更多
登录 后发表回答