【发布时间】:2016-10-17 07:16:56
【问题描述】:
我有一个表格供用户填写。在服务器端,我使用 mailgun 在表单提交后发送电子邮件。
出现错误时,我想显示一个 toast 对话框(Javascript 中的Materialize.toast("Error", 2500);)。由于错误检查发生在服务器端,我不知道如何调用该方法。
我碰巧在 HTML 中使用<script> 来阻止页面在提交时刷新——但我不知道如何处理这个<script> 中的错误。这里是:
<script type="text/javascript">
$("#contact-form").submit(function(e) {
e.preventDefault(); // Prevents the page from refreshing
var $this = $(this); // `this` refers to the current form element
$.post(
$this.attr("action"), // Gets the URL to sent the post to
$this.serialize(), // Serializes form data in standard format
function(data) {
},
"json" // The format the response should be in
);
Materialize.toast("Toasty McToastface!", 1000);
$('#contact-form').trigger('reset');
});
</script>
感谢所有帮助。
【问题讨论】:
标签: javascript html node.js materialize