如何显示警报框?

时间:2014-01-07 09:34:09

标签: javascript php

以下代码实际提交,并且我需要显示一个警告框,显示已发送消息。

代码:

<input type="button" class="Jdvs_Btn" onclick="send_reply('SEND_REPLY', <? echo $clsSurvey->feedback_id?>);" value="SEND" style="font-weight:bold;width:95px;height:30px;float:left; margin-right:5px;" />

和Javascript

代码:

if(action == "SEND_REPLY")
{
if( frm.email.value == "" )
{
   alert("Please fill your email.");
   frm.email.focus();
   return false;
}   
else if( validateEmailAddress(frm.email.value) == false )
{
    alert("Please fill a valid email.");
    frm.email.focus();
    return;
}
else if ((tinymce.EditorManager.get('content_to_send').getContent()) == '')
{
    alert("Please enter content to send.");
    return;
}
else
{
    frm.form_action.value = action;
    frm.submit(); 
    alert('Message Sent Successfully');
}

}

邮寄代码是: 这是验证和其他完成的地方,我需要在这里显示一个警告框 代码:

function sendReply()
{
    echo $this->feedback_id;
    $this->checkAndUpdateReply($this->feedback_id,$this->content_to_send);
    $Message = nl2br($this->content_to_send);
    $mailMessage = "
    <html>
    <head>
    <title>constant('_SHORT_PRODUCT_NAME') - Feedback Mail</title>
    </head>
    <body>";
            $Message = nl2br($this->content_to_send);
        $mailMessage.= $Message."
    <table border='0' cellpadding='0' cellspacing='0'width='100%'>
    <tr>
    <td style='$css_class' align='left'><br/>Email: "._EMAIL_INFO."</td>
        </tr>
        <tr>
        <td style='$css_height' align='left'><br /><b>Note</b>:- This is an automatically generated email , Please dont reply back to this mail.</td>
    </tr>
        </table>
    </body>
    </html>";    
    $mailSubject= constant('_SHORT_PRODUCT_NAME').' - FeedBack Reply';
    $clsEmailTempalte = new clsEmailTemplate($connect, ""); 
    $clsEmailTempalte->sendMail($mailSubject,$mailMessage,$this->email);
}

4 个答案:

答案 0 :(得分:2)

send_reply javascript函数结束时,只需执行alert("Mail Sent");

如果您正在使用ajax(例如使用jQuery),则需要将警报添加到回调中。

对于jQuery:

var jqxhr = $.ajax( "example.php" )
  .done(function() {
    alert( "success" );
  })

答案 1 :(得分:0)

在您的javascript函数send_reply中添加

alert("Message sent");

应该有效。

答案 2 :(得分:0)

只需将alert("message has been sent");放在js函数的末尾。

答案 3 :(得分:0)

如果我这样做(使用jQuery)。我会调用使用ajax发送电子邮件的php文件:

您的HTML:

<input type='button' id='submit_form' data-id='<? echo $clsSurvey->feedback_id?>' />

您的Javascript:

$('#submit_form').click(function(e){

    // To stop the form submitting on button click if you want it to...
    e.preventDefault();

    // Send the id via post to the mailscript
    $.ajax({
        url: 'mailscript.php',
        type: 'POST'
        data: {
            id: $(this).attr('data-id')
        }
    }).done(function(data){
        // Use data if you want to return something from the script and add to the message maybe?
        alert('Add your message in here');
    });

});

然后只需在mailscript.php(或任何你想要的名字)中添加你的邮件php。只要你的脚本完成了它的工作,就会触发完成功能显示你的警报。

相关问题