這是應該做到這一點給你一個函數:
//'step' indicates the current iteration of the posting loop, and 'limit' tells it after how many iterations to stop. If you want to post to 5 of 5 forums, set 'step' to 1 and 'limit' to 5.
function submitSteps(step, limit)
{
if (step <= limit)
{
$.ajax({
url: 'http://example.com',
data: 'postTo='+step,
beforeSend: function()
{
if ($('#notice p:last').html().indexOf('problem') > -1)
{
$('#notice p:last').remove();
}
$('#notice').append('<p>Posting to forum '+step+'...</p>');
},
success: function()
{
$('#notice p:last').remove();
$('#notice').append('<p>Post to forum '+step+' complete!</p>');
window.setTimeout('submitSteps(step+1, limit)', 1000);
},
error: function()
{
$('#notice p:last').remove();
$('#notice').append('<p>There was a problem posting to forum '+step+'.</p>');
window.setTimeout('submitSteps(step, limit)', 1000);
}
}
}
難道我得到這個權利:要攔截`form`的`submit`行動並從那裏執行一系列AJAX請求? – 2011-12-15 23:41:32