Asp.Net Core MVC传值 Asp.Net Core API 前台写法

时间:2020-06-06 11:06:13   收藏:0   阅读:96

$("#Add_User").click(function () {
var obj = {
 //"属性名": 传递的值,
"User_Name": $("#User_Name").val(),
"User_PassWord": $("#User_PassWord").val(),
"User_Email": $("#User_Email").val(),
"User_Phone": $("#User_Phone").val(),
"User_Card": $("#User_Card").val()
};
$.ajax({
url: "默认地址/api/控制器方法/动作方法名,
type: "post",
dataType: "json",
data: obj,
accepts: "application/x-www-form-urlencoded",  //非加不可
contentType: "application/x-www-form-urlencoded",  //非加不可
success: function (data) {
console.log(data);
if (data > 0) {
alert(‘添加成功!‘);
} else {
alert(‘添加失败!‘);
}
}
});

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!