jQuery提交时如何处理错误消息

时间:2018-12-18 10:23:36

标签: javascript jquery asp.net-mvc form-submit

我有一个局部视图,我试图尝试从客户端代码提交表单。一切正常。

但是现在我们需要处理一些错误/验证消息,这些消息是根据适当的验证从服务器发送过来的(理想情况下显示警报/敬酒消息)。我不清楚要添加什么代码来实现相同的效果

这是当前的代码:

$('#myForm').submit(function (e) {
   var isFormValid = true;
   //Client side validations sit here 
   if (isFormValid) {
     //How do I handle the error message returned here?
   }else
     e.preventDefault();
   }
}

TIA

1 个答案:

答案 0 :(得分:-2)

获取一个变量,无论结果是成功还是失败, 然后使用boostrap

import platform
import os
import browserhistory as bh
def printTohtml(htmlfile):    
    html =  "<html>\n<head></head>\n<style>p { margin-bottom:5px  !important;  }</style>\n<body>\n"

    title = "Browser History"
    html += '\n<p style = "background-color: #92a8d1 !important; color:white !important; font-size:24px !important; text-align: center !important; letter-spacing: 5px !important; ">' + title + '</p>\n'


    para = '<p style = "background-color: #92a8d1 !important; color:white !important; font-size:24px !important; text-align: center !important; letter-spacing: 5px !important;">' + browserhistory1 + '</p>\n'
    html += para
    dict_obj = bh.get_browserhistory()
    for i in range(0 ,19):
        html += '<p style = "white-space: pre-line !important; line-height: 28px !important;">' + str(dict_obj['firefox'][i]) + '</p>\n'

    with open(htmlfile, 'w') as f:
        f.write(html + "\n</body>\n</html>")

browserhistory1 = ("Browser History")

printTohtml('firefox.html')