jQuery 各种异步请求的发送形式

文章目录

  • 1、post发送表单文件的ajax
  • 2、get发送key-value键值对
  • 3、post发送json对象,发送前必须使用JSON.stringify( JSONObject )
  • 4、post发送整个表单序列化数据
  • 5、put 请求发送整个表单序列化数据
  • 6、delete请求发送待删除记录的主键
  • 7、

1、post发送表单文件的ajax

    $.ajax({
        type: "post",
        url: "/stu/import",
        data: formData,
        contentType: false, // 使用form的 enctype
        processData: false, // 不对form表单的数据进行处理
        success: function (data) {
            console.log(data);
            stuCourseInfo = data;
            joins(data);
        }
    });

2、get发送key-value键值对

    $.ajax({
        type: "get",
        url: "/stu",
        data: {"curpage":1},
        success: function (data) {
            console.log(data);
            joins(data);
        }
    })

3、post发送json对象,发送前必须使用JSON.stringify( JSONObject )

    $.ajax({
        type: "post",
        url: "/stu",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(stuCourseInfo),
        success: function (data) {
            console.log(data);
        }
    })

4、post发送整个表单序列化数据

    $.ajax({
        type: "post",
        url: "/teacher",
        data: $("form").serialize(),
        dataType: 'text',
        success: function (data) {
            console.log(data);
        }
    })

5、put 请求发送整个表单序列化数据

    $.ajax({
        type: "put",
        url: "/teacher",
        data: $("form").serialize(),
        dataType: 'text',
        success: function (data) {
            console.log(data);
        }
    })

6、delete请求发送待删除记录的主键

   $.ajax({
       type: "delete",
       url: "/schedule",
       data: {"id" : curClickTd.attr("id")},
       dataType: 'text',
       success: function (data) {
           console.log(data);
           tr.remove();
       }
   })

7、

你可能感兴趣的:(前端开发,ajax,jquery,json)