创建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.

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

Your waiting message is inside the div with id load and not waiting. You should change the following

<div id="load" style="display:none;">Please wait.</div>

to

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