[英]How to display an alert box?
以下代碼實際提交,並且我需要顯示一個警告框,顯示已發送消息。
代碼:
<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);
}
在send_reply
javascript函數結束時,只需執行一個alert("Mail Sent");
如果您正在使用ajax(例如使用jQuery),則需要將警報添加到回調中。
對於jQuery:
var jqxhr = $.ajax( "example.php" )
.done(function() {
alert( "success" );
})
在你的javascript函數send_reply
只需添加該行
alert("Message sent");
應該管用。
只需alert("message has been sent");
在你的js函數結束時。
如果我這樣做(使用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。 只要您的腳本完成了它的工作,就會觸發完成功能顯示您的警報。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.