php - jQuery - 如何通过不同的步骤获得响应?

标签 php javascript jquery ajax

我想要一个 ajaxed 表单,当用户单击“提交”时,它将把表单值提交到 php 文件,这里没有什么花哨的,到那时我就清楚了。

现在我想从服务器获得几个响应来存储在响应 div 中。

例如,该表单用于撰写帖子,然后我的 php 文件将该帖子发布到 5 个不同的论坛,我想在结果中准确显示它的作用

发帖到论坛 1...然后清除该选项并显示发帖到论坛 2...

我想显示脚本当前在 jquery 输出 div 中正在做什么,我的问题是如何做到这一点?请告诉我jquery 中的代码要求以及PHP 中的代码要求。

预先感谢您的帮助

最佳答案

这是一个可以为您完成此任务的函数:

//'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);    
        }
    }
}

关于php - jQuery - 如何通过不同的步骤获得响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8528091/

相关文章:

php - 使用 MySQL PDO 显示每种费用类型下的费用

php - 在 WooCommerce 结帐中为特定选择的运输方式添加主体类

javascript - 通过单击图像将 1 求和到一个值 - PHP

php - Symfony2 中生成的 URL 的用例?

javascript - React.js .push() 不是函数

javascript - 合并音频文件 - node js

javascript - jQuery icheck 插件在追加后不起作用

javascript - 测试 IOS Safari anchor 链接

javascript - 如何在不刷新页面的情况下使用 jQuery 和 Ajax 在 MySQL 中插入数据

javascript - jQuery Masonry 没有重新加载?