如果响应有效,则显示window.alert

时间:2014-08-09 05:16:00

标签: javascript php alert

嗯......我试过了:

if ($resp->is_valid) {
    @mail($email_to, $email_subject, $email_message, $headers);
    print "<script language="javascript">
    window.alert("'Thank you for submitting the track. We will be in touch with you very soon. Click 'Ok' to redirect you to the Homepage.'")
    window.location.href='http://www.xmasterofficial.tk/'
    </script>";
} else {
    echo "Sorry cannot send email as you've failed to provide correct captcha! Try again...";
}

我不知道是什么问题。如果$ resp有效,它应该创建一个window.alert,否则创建一个消息。 window.alert没有显示。

2 个答案:

答案 0 :(得分:1)

代码在print语句中使用引号时遇到一些问题。在使用多个字符串处理时使用echo而不是print。您需要单独处理引号才能使用此函数帮助您处理警报选项。

if ($resp->is_valid) {
@mail($email_to, $email_subject, $email_message, $headers);
echo "<script language='javascript'>
window.alert('Thank you for submitting the track. We will be in touch with you very soon. Click Ok to redirect you to the Homepage.')
window.location.href='http://www.xmasterofficial.tk/'
</script>";
} else {
echo "Sorry cannot send email as you have failed to provide correct captcha! Try again...";
}

答案 1 :(得分:0)

if ($resp->is_valid) {
@mail($email_to, $email_subject, $email_message, $headers);
echo "<script type='text/javascript'>
alert('Thank you for submitting the track. We will be in touch with you very soon. Click Ok to redirect you to the Homepage.');
window.location.href='http://www.xmasterofficial.tk/';
</script>";
} else {
echo "Sorry cannot send email as you have failed to provide correct captcha! Try again...";
}