weixin_33739646 2014-07-20 15:33 采纳率: 0%
浏览 64

5秒后调用Ajax

If I click on a button is it possible to call an ajax after 5 secs?

HTML :

<button>Click</button>
<p id='output'></p>

AJAX:

$('button').click(function() {
    $.ajax({
        type: 'post',
        url: 'save_student_db.php',
        data: 's_name=' + $('#s_name').val() +
            '&s_email=' + $('#s_email').val() +
            '&s_phone=' + $('#s_phone').val() +
            '&s_add=' + $('#s_add').val() +
            '&dept_select=' + $('#dept_select').val() +
            '&datepiker=' + $('#datepiker').val(),
        success: function(reply_data) {
            $('#output').html(reply_data);
        }
    });
});

Here I want when I click on the button then this ajax call will called after 5 secs. How can I do it? thank you.

  • 写回答

2条回答 默认 最新

  • helloxielan 2014-07-20 15:35
    关注

    You can use setTimeout()

    setTimeout(function(){ $(".selectSomething").yourAjaxFunctionHere() }, 5000);

    评论

报告相同问题?