jquery提交表单mvc3后台处理示例
程序员文章站
2024-02-25 22:43:45
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;
}