zoukankan      html  css  js  c++  java
  • $.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
    
    爱生活、爱编程!
  • 相关阅读:
    Project项目视图
    Console(控制台视图)
    Layout布局列表
    Layers层列表
    帐户下拉
    TransformGizmo(变换)切换
    Play播放控件
    变换工具
    工具栏
    Help帮助
  • 原文地址:https://www.cnblogs.com/liliuyu/p/14539097.html
Copyright © 2011-2022 走看看