Hardrik
Hardrik

Reputation: 398

auto load in ajax jquery on every one minute

$('.msg_block').on('click', 'section.msgholder', function(event) {

         var clickedItem = $(this).attr('id');
         var id = jQuery(this).data('value');
        var date = jQuery(this).data('date');
        $.ajax({
                    type:"POST",
                    url:"/Messages/messageDetails", 
                    data: {id: id, ddate: date},
                    beforeSend: function()
                    {

                    },
                    success : function(response) {
                        // Do all my stuff here
                   },
                    error : function() {
                        alert('error');
                    }
                });             
    });

This is my simple jquery ajax call to the server. Now i want to fire this ajax request every second. Could anyone please help me in this.

Any help would be appreciable.

Upvotes: 1

Views: 3293

Answers (2)

niket kale
niket kale

Reputation: 11

Try this to call your AJAX function after every one minute

$(document).ready(function () {
    setInterval(function () {
        SomeFunction();
    }, 60000); // 1000 ==> 1 second
});

function SomeFunction() {
    $(".msg_block").click();
}

Upvotes: 1

Sridhar R
Sridhar R

Reputation: 20408

You can use setInterval. Look:

window.setInterval(event, 60000); // It will call the function every 1 min

And function event would be

function event() {
 $(".msg_block").click(); // it will click that class so ajax function called
}

Upvotes: 0

Related Questions