简体   繁体   English

如何在AJAX表单提交请求期间显示实时脚本输出?

[英]How to show live script output during AJAX form submit request?

How to show "Live Feedback" on a script using jQuery? 如何使用jQuery在脚本上显示“实时反馈”?

I have a button that I use to submit a form for processing. 我有一个button ,用于提交要处理的表单。 Processing takes a long time. 处理需要很长时间。 I want to have a <div id="progress"></div> where I show live progress report of what order processing script is doing. 我希望有一个<div id="progress"></div> ,在其中显示有关订单处理脚本正在执行的实时进度报告。 If all goes well I want to redirect to the View Order script, and if not, just show the progress report (not redirect to view order) 如果一切顺利,我想重定向到“查看顺序”脚本,否则,只显示进度报告(不重定向到查看顺序)

How? 怎么样? Currently I have this: 目前我有这个:

$("#placeorderbutton").click(function(e) {
    e.preventDefault();
    this.innerHTML = 'Placing Order...';
    this.disabled = true; 
    $.ajax({
        type: 'post',
        url: 'process_order.php',
        data: $('form#order').serialize(),
        success: function(data) {
            $("#main").load('view_order.php');            
        }
    });
}); 

and even though I have print statements in my process_order file, they are not being displayed anywhere on the screen. 即使我的process_order文件中有打印语句,它们也不会在屏幕上的任何位置显示。 Well, of course not ... I don't know how to build my jQuery/AJAX to make them show. 好吧,当然不是...我不知道如何构建我的jQuery / AJAX以使其显示。

I am not sure how to proceed. 我不确定如何进行。

You would need to start the long process and then start a timer to poll the status. 您将需要开始漫长的过程,然后启动计时器以轮询状态。 Keep in mind it doesn't take much for this to become more expensive than it's worth. 请记住,这变得比价格昂贵更昂贵。

$("#placeorderbutton").click(function(e) {
    e.preventDefault();
    this.innerHTML = 'Placing Order...';
    this.disabled = true; 
    $.ajax({
        type: 'post',
        url: 'process_order.php',
        data: $('form#order').serialize(),
        success: function(data) {
            $("#main").load('view_order.php');            
        }
    });
    setTimer($.ajax({
        type: 'post',
        url: 'view_order.php',
        data: $('form#order').serialize(),
        success: function(data) {
            $("#main").append(data);            
        }
    }), 30000);  //check every 30 Seconds
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM