Click here to Skip to main content
14,878,805 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
$(document).ready(function () {

    // Hide the "busy" Gif at load:
    $("#fade").hide();

    // Attach click handler to the submit button:
    $('#process').click(function () {
        $('#myform').submit();
        $("#fade").css("display", "block");
        $('#fade').css({ 'width': 8000, 'height': 8000 })
                         .fadeIn(10).fadeTo('slow', 0.7);

        // Handle the form submit event, and make the Ajax request:
        $("#myform").on("submit", function (event) {
            event.preventDefault();

            // Show the "busy" Gif:
            $("#fade").show();
            var url = $(this).attr("action");
            var formData = $(this).serialize();
            $.ajax({
                url: url,
                type: "POST",
                data: formData,
                dataType: "json",
                success: function (resp) {
                    // Hide the "busy" gif:
                    $("#fade").hide();
                    // Do something useful with the data:
                }
            })
        });
    });
});
<div id="fade" class="fade" style="display: none; text-align: center;    z-index: 9999999999;">
                       <img src='@Url.Content("~/images/loadingg3.gif")' style="top: 60%;position: fixed; left: 1%;" width="150" height="150"/>
                   </div>


What I have tried:

I want to for submit on Loader.when click on submit button,please give me any suggestion .
Posted
Updated 13-Apr-16 23:03pm
v2

1 solution

Try re-ordering, note I've also amended the html to make it work with IE.

HTML
<div id="fade" class="fade" style="display: none; text-align: center;    z-index: 9999999999;">
    <img src='@Url.Content("~/images/loadingg3.gif")' style="opacity: inherit; filter: inherit; top: 60%; position: fixed; left: 1%;" width="150" height="150" />
</div>

<form id="myform" action="/home/GetData" method="post">
    <input type="text" name="MyText" />
    <input type="submit" value="Submit" />
</form>

<a href="#" id="process">Process</a>

<script type="text/javascript">
    // Handle the form submit event, and make the Ajax request:
    $("#myform").on("submit", function (event) {
        event.preventDefault();

        // Show the "busy" Gif:
        $('#fade').fadeTo('slow', 0.7);

        var url = $(this).attr("action");
        var formData = $(this).serialize();
        
        $.ajax({
            url: url,
            type: "POST",
            data: formData,
            dataType: "json",
            success: function (resp) {
                // Hide the "busy" gif:
                $("#fade").hide();
                // Do something useful with the data:
                alert(resp.result);
            }
        })
    });

    $('#process').click(function () {
        $('#myform').submit();
    });
</script>




Controller

C#
public ActionResult GetData(FormCollection form)
{
    // injecting an artifical delay so the loader can be seen
    System.Threading.Thread.Sleep(3000);

    return Json(new { result = form["MyText"] });
}
   
v3
Comments
AnantPithadiya 14-Apr-16 5:09am
   
Sorry,Not working.resp not get
F-ES Sitecore 14-Apr-16 5:42am
   
I've updated my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900