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...
    $$('.links').observe('click', function(e) {

    (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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 使用matlab计算自定义特殊函数的二重积分,改变积分顺序所得的结果不同的问题?
  • ¥15 mysql做碎片化处理老是报错怎么办
  • ¥15 如何正确在vs2010中初始化map对象
  • ¥30 mmdet3d模型部署问题
  • ¥15 comsol仿真反射率、吸收率时峰值位置和深度不对!
  • ¥30 Visual Studio找不到sdk,如何解决?
  • ¥15 labview与机器之间网口通信发送指令
  • ¥15 迪杰斯特拉算法,考虑时延,带宽
  • ¥30 C#提交json字符串给http服务器
  • ¥15 CondaValueError: Malformed version string '~': invalid character(s).