Dave Mateer
Dave Mateer

Reputation: 6626

Javascript poll and submit

Am trying to get my 'Allocate auto every minute' button below to keep submitting itself every minute.

Using ASP.NET MVC3

enter image description here

Polling in javascript something like this.. which when I click the click button it keeps firing every 3 secs. But how to get it to fire off a submit to the back end... hmm - this feels like an async call to MVC.

   <script type="text/javascript">
var intervalId = 0;

$(function() {
    $('input[name=click]').bind('click', function() {
        $('.discussion').append('<div class="replyarea">some content in here plus</div>');
        intervalId = setInterval(fadeDiscussion, 3000); // start the timer
    });
});

var i = 1;
function fadeDiscussion () {
    console.log(i);
    $('.discussion').fadeOut().fadeIn();
    $('.discussion').append('<div class="replyarea">polled</div>');
    i++;
}
</script>

enter image description here

thanks to JQuery auto refresh (setInterval)

Upvotes: 0

Views: 225

Answers (1)

Roman
Roman

Reputation: 10403

Use the post function in jQuery. http://api.jquery.com/jQuery.post/

jQuery.post(URL, [data,] [success(data, textStatus, jqXHR),] [dataType]);

$.post("xxx.html", {}, function(data, textStatus, jqXHR){
    alert("async request was completed");
});

Upvotes: 1

Related Questions