locked
Ajax Update Div RRS feed

  • Question

  • User-957910121 posted

    In my MVC application I have a particular div I want to update without any postbacks, I obviously thought of Ajax to accomplish this but was wondering how I would acheive this behaviour.  I want the div to update at set intervals using ajax.  Can anyone help with this?

    Wednesday, December 2, 2015 1:52 PM

Answers

  • User61956409 posted

    Hi Yanayaya,

    In my MVC application I have a particular div I want to update without any postbacks, I obviously thought of Ajax to accomplish this but was wondering how I would acheive this behaviour.  I want the div to update at set intervals using ajax.  Can anyone help with this?

    Window setInterval() method could execute a function at specified intervals. And you could dynamically update html based on return data in AJAX success callback function.

    function myfunction() {
        setInterval(function () {
            //send ajax request 
            $.ajax({
                type: "Post",
                url: "yourwebmethod",
                //...
                //other options
                success: function (data) {
                    //update div
                },
                error: function (err) {
                    alert(err);
                }
            })
        }, 5000)
    }
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 3, 2015 6:15 AM