小程序Post请求

目的:做到小程序和MvcApi的数据交互

1.wxml

<button bindtap='postliuyan'> 留言post</button>

2.js

postliuyan:function(e)

{

wx.request({

url: 'http://localhost:40637/api/values/',

data:{

id:1,

name:'xiaohong'

},

method: "POST",

dataType:JSON,

success: function (res) {

console.log(res.data)

},

})

},

3.MVCApi
        // POST api/values
        public JObject Post([FromBody]JObject value)
        {
            var cc = value;

            Staff staff = new Staff();
            staff.Id = 2;
            staff.Name = "xiaohong";

           JObject jsonObj= JObject.FromObject(staff);
            return jsonObj;


        }

猜你喜欢

转载自blog.csdn.net/weixin_42401291/article/details/83896287