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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵