WebAPI的使用

后台API的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.Cors;

namespace ECERP.Web.Controllers
{

  //有参数的POST请求 [RoutePrefix("api")] [EnableCors(origins: "*", headers: "*", methods: "*")] public class SignInController: ApiController { [HttpPost, Route("SignIn/SignIn")] public void SignIn([FromBody]SignInDto signInDto) { } } public class SignInDto { /// <summary> /// 设置的Id /// </summary> public string Id { get; set; } } }

前台JS代码:

//有参数的POST请求
var data={Id: "1"};
$.ajax({ type: "post", url: "/api/SignIn/SignIn", data: JSON.stringify(data), cache: true, contentType: "application/json",//必须是这个 //contentType: false,//上传文件用这个 dataType: "json", success: function (data, status) { }, error: function (e) { }, complete: function () { } });

  

posted @ 2019-09-24 17:50  enjoryWeb  阅读(154)  评论(0编辑  收藏  举报