学无先后,达者为师

网站首页 编程语言 正文

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

作者:小徐敲java 更新时间: 2024-04-04 编程语言

$.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);
    }
});

原文链接:https://blog.csdn.net/qq_19891197/article/details/135861642

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新