$.ajax 请求数据

jquery 请求后台数据 要把json对象 转换 字符串。 通过JSON.stringify 转字符串 才能通过与后端交互 请求数据。

       $.ajax({
        type: "post", // 请求类型 GET/POST
        contentType: "application/json; charset=utf-8",
        url: "https://thsdfasdfttcst.cpic.com.cn/thc-app/receiveData", // 测试请求路径
        data:JSON.stringify({ "actId":actId,"listId":listId,"nodeId":nodeId,"clickDate":clickDate,"channelSource":channelSource}),
        dataType: "json",
        // crossDomain: true,   // 会让请求头中包含跨域的额外信息,但不会含cookie
        success: function (res) { // 请求成功时的回调函数
        console.log(res);
          if(res.code == 0){
            console.log('成功')
          }
        }
      });
//提交json数据
 $(document).ready(function () {
        $.ajax({
            type: "POST",
            url: "/LoginServlet",
            contentType: "application/json;charset=utf-8",
            data:JSON.string({"name":"yd","pwd":"123456"}),
            dataType: "json",
            success:function (message) {
                alert("提交成功"+JSON.stringify(message));
            },
            error:function (message) {
                alert("提交失败"+JSON.stringify(message));
            }
        });
     });x
posted @ 2021-03-15 17:55  打个大大西瓜  阅读(135)  评论(0编辑  收藏  举报