config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
public class UserModel
{
public string UserID { get; set; }
public string UserName { get; set; }
}
public class UserController : ApiController
{
public UserModel getAdmin()
{
return new UserModel() { UserID = "000", UserName = "Admin" };
}
}
$.ajax({
type: 'GET',
url: 'api/user/getadmin',
dataType: 'json',
success: function (data, textStatus) {
alert(data.UserID + " | " + data.UserName);
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
}
});
public bool add(UserModel user)
{
return user != null;
}
<input type="button" name="btnOK" id="btnOK" value="发送POST请求" />
$('#btnOK').bind('click', function () {
//创建ajax请求,将数据发送到后台处理
var postData = {
UserID: '001',
UserName: 'QeeFee'
};
$.ajax({
type: 'POST',
url: 'api/user/add',
data: postData,
dataType: 'json',
success: function (data, textStatus) {
alert(data);
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
}
});
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有