dty47696 2012-10-11 15:44
浏览 174
已采纳

在表单提交和重定向之间显示“请等待”

I have a page that contains an HTML form that submits back to itself once the user clicks a link in a list of returned search results. Once they click the link, the page takes the submitted variables, runs a bunch of searches on various external APIs, parses a bunch of data, and adds a bunch of stuff to the database, then redirects to a new page that has been created from that data.

All the searching and parsing can take up to six or seven seconds; I'd like to be able to show the user a "Please Wait" kind of message while all that work is happening behind the scenes.

Trouble is, I can't show and hide a DIV because it will screw up my PHP redirect if I've already generated output before the

header('Location: ' . $newURL);

command. I've searched around for answers but while there are many that are similar, none of them are close enough to my specific situation that I can hack around them.

I'd be grateful if someone could point me in the right direction.


Updated version which now works, courtesy @Izkata from his comments below:

jQuery("a").bind('click', function() {
  jQuery('#feedback')[0].innerHTML = 'Searching, please wait...';
})

Turned out what I needed to do was assign bind a the message to the click of a link, not to 'submit', as submit was looking for form data.

  • 写回答

3条回答 默认 最新

  • dua27031 2012-10-11 15:48
    关注

    The simplest way I can think of doesn't require the server to do anything:

    <div id='wait_message' style='display: none;'>
       Please wait while search is in progress...
    </div>
    
    ...
    
    $$('.links').observe('click', function(e) {
       $('wait_message').show();
    });
    

    (Event is written using Prototype.js; you should use whatever is appropriate (JQuery/mootools/etc))


    Using the example page in the comments, this works - it runs in Firebug, so just putting it on your page somewhere should work just fine.:
    jQuery('#newMovieSearchForm').bind('submit', function() {
       jQuery('#feedback')[0].innerHTML = 'Searching, please wait...';
    })
    

    There's probably a jQuery-way to update the text instead of using innerHTML, but I don't know it - we don't use jQuery here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突