dongwei1954 2014-03-03 21:52
浏览 47

创建PDF后隐藏AJAX消息

I am submitting a form using php and ajax. The form sends HTML output to a different page that creates a pdf. The submit is working fine, but I can't seem to hide to the waiting message after the pdf is created. I have tried a few different ways without success.

Here is the form code:

<div id="message" style="display: none;"></div>
<div id="waiting" style="display: none;">Please wait</div>

<form action="/export-to-pdf" method="POST" id="pdfform" >
    <input type="hidden" name="var1" value="<?=$var1;?>">
    <input type="hidden" name="var2" value="<?=$var2;?>">
    <input type="submit" id="pdfsubmit" name="pdfsubmit" value="Submit">
</form>

Here is the important code from the page that creates the pdf:

$pdf->Output('form.pdf', 'D');
    $return = array();
    $return['success'] = "success";
    echo json_encode($return);

Here is the script:

$(document).ready(function(){
$('#pdfsubmit').click(function() {

    $('#waiting').show(500);
    $('#pdfform').hide(0);
    $('#message').hide(0);

    $.ajax({
        type : 'POST',
        dataType : 'jsonp',
        url : '/export-to-pdf',
        data: serialize(),
        success : function(response){
        if (response.success == 'success') {
            $('#waiting').hide(500);
            $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
                .text(data.msg).show(500);
            if (data.error === true)
                $('#pdfform').show(500);
            }
        }
        ,
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            $('#waiting').hide(500);
            $('#message').removeClass().addClass('error')
                .text('There was an error.').show(500);
            $('#pdfform').show(500);
        }
    });

    return false;
});

});

A "Save As" dialog box is shown once the pdf is ready for download, but the ajax message still appears on the screen and never goes away. I am using TCPDF class to build the pdf file.

  • 写回答

2条回答 默认 最新

  • douyu0792 2014-03-03 21:55
    关注

    It looks like your please wait is in the load div... not that waiting div... $('#load').hide(0);

    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示