ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

jQuery实现ajax语法,post请求发送数组对象(jquery)

jQuery实现ajax语法,post请求发送数组对象(jquery)

$.ajax()代码模板

jQuery实现ajax语法为:$.ajax({}),其中{}为对象,对象里面的key键是固定的,比如:
1、type: 表示请求方式,一般为post或get
2、url表示请求的地址
3、contentType表示发送信息至服务器时内容编码类型
4、data表示发送到服务器的数据
5、dataType表示预期服务器返回数据的类型如:text,json,xml等等类型
6、success表示请求成功后的回调函数
7、error自动判断 (xml 或 html)。请求失败时调用此函数,等等

对象中包含数组对象

let htLockRelationCard = {userList: userList,roomId: roomId,cardNumber: cardNum
};
$.ajax({url: `smartLockRoomRelationCard/cardDelivery`,type: "POST",contentType: "application/json",data: JSON.stringify(htLockRelationCard),dataType: "json",success: function (res) {console.log(res);}
});

数组对象

$.ajax({url: `smartLockRoomRelationCard/cardDelivery`,type: "POST",contentType: "application/json",data: JSON.stringify(userList),dataType: "json",success: function (res) {console.log(res);}
});
返回列表