Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

Ajax call every minute using jQuery

by
Category:javascript
php ajax javascript jquery
Ajax call every minute using jQuery

As of these days most social networking sites are using this event to load most recent posts every second without refreshing page, stream and tweets like Facebook, Google+ and Twitter, it loads in the top part of the page and I’d try developed one with jQuery and Ajax to mimic this functionality, it’s really simple and easy to use. You may also like How to Interval Timer Countdown using setTimeout() and How to get Page Loading Time using PHP.

Jquery Code

<script type="text/javascript">
    var i = 60;
    var myVar;
    function onTimer() {
        $('#mycounter').html(i);
        $('#timer_count').val(i);
        i--;
        if (i < 0)
        {
            getQuizinformation();
        } else
        {
            myVar = setTimeout(onTimer, 1000);
        }
    }
    onTimer();

    function getQuizinformation()
    {
        var formData = new FormData();
        var contact = $('#QuestionQuiz').serializeArray();
        $.each(contact, function (key, input) {
            formData.append(input.name, input.value);
        });

        $.ajax({
            type: 'POST',
            url: "submitquiz.php",
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'JSON',
            success: function (data) {
                i = 60;
                clearTimeout(myVar);
                onTimer();
                if (data.studentflag == 1)
                {
                    alert(data.message);
                }
            }
        });
    }
</script>

0 Comments


Html code work in comment box


Related Post