欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jquery提交表单mvc3后台处理示例

程序员文章站 2024-02-23 11:21:52
jquery提交表单 复制代码 代码如下:$(document).ready(function () {     &nb...

jquery提交表单

复制代码 代码如下:

$(document).ready(function () {
           $("#btnlogin").click(function () {
               $.ajax({
                   url: '/home/login',
                   data: '{ "account":"' + $("#account").val() + '", "psword": "' + $("#psword").val() + '" }',
                   type: "post",
                   contenttype: "application/json;charset=utf-8",
                   datatype: "json"
                   ,
                   success: function (data) {
                       if (data != "")
                           alert(data);
                       else
                           location.href = "/home/index"                  
                   }
               });
           });
       });

mvc3后台处理:

复制代码 代码如下:

[httppost]
        public actionresult login(string account, string psword)
        {
            jsonresult result;
            if ("" == account && "" == psword)
                result = this.json("");            
            else
            {
                result=this.json("用户或密码不正确");               
            }          
            return result;

        }