Run asp.net mvc ajax update automatically every X minutes

I have a Refresh button on my page that will execute an asp.net mvc ajax message to refresh some of the content on the page. The update / update process can take a long time (about 10-20 seconds). Right now, the user needs to manually click the "Update" button to trigger the update. I want to automatically start the update every X minutes. To a large extent, I want to run the same Ajax post as shown below (and it would be nice to display LoadElementId as well).

<% using (Ajax.BeginForm("Refresh", null, 
                   new {userId=Model.UserId},
                   new AjaxOptions { UpdateTargetId = "UserForm", LoadingElementId = "RefreshingDiv" },
                   null))
               {
            %>

                    <button type="submit">
                        <img src="/zsys/img/icons/refresh.png" alt="Refresh" />
                        Refresh
                    </button>

            <% } %>

How can I force an asp.net mvc ajax to be returned?

+3
source share
3 answers

Wyatt Barnett "" . setInterval "" 5 :

    <script src="../../scripts/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            setInterval("$('#RefreshFormButton').click()", 300000);
        });
    </script>
+5

jQuery + call $('#form').submit() .

0

Put RefreshFormButton in the id submit button .... well, you get a JS function.

0
source

Source: https://habr.com/ru/post/1719995/


All Articles