
对于简单类型,在服务器端:
public void Post([FromBody]string name){} var dataJSON = "test"; $('#testPostMethod').bind("click", GeneralPost); function GeneralPost() { $.ajax({ type: 'POST', url: '/api/NewRecipe', data: JSON.stringify(dataJSON), contentType: 'application/json; charset=utf-8', dataType: 'json' }); }如果要使其以复杂类型工作,则应从服务器端定义:
public class RecipeInformation{ public string name { get; set; }}public class ValuesController : ApiController{ public void Post(RecipeInformation information) { }}从客户端:
var dataJSON = { name: "test" }; $('#testPostMethod').bind("click", GeneralPost); function GeneralPost() { $.ajax({ type: 'POST', url: '/api/NewRecipe', data: JSON.stringify(dataJSON), contentType: 'application/json; charset=utf-8', dataType: 'json' }); }欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)