Fork me on github

ajax请求

请求示例

ajax post请求multipart/form-data

   /**
     * ajax post请求
     * 请求方式 multipart/form-data
     * 携带token
     * contentType : false, processData : false,(必须)
     * 参数:FormData形式
    */
var formData = new FormData();
formData.append('message','wwewewewewe')
var token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMmIwNGNmMi0xZWJkLTQzMzctODQ3ZS1iNDg2YTAxMjNhNTYiLCJhY291bnQiOiJhZG1pbl9uaWtveW9zZV8zMDMzNjU0MzYyIiwicGFzd2QiOiJhZG1pbl9uaWtveW9zZV8zMDMzNjU0MzYyIiwiYXBwaWQiOiIxMzA4MzM5MDcwIiwibmJmIjoxNjY4OTk1MTM2LCJleHAiOjE2NjkwODE1MzYsImlzcyI6Im5rbyIsImF1ZCI6InVzZXIifQ.YWEe-6juRu6DKd5pmdPnLbjkAV6S1ls38gxrRCeaz9s"
    $.ajax({
        url: "http://192.168.253.217:7783/api/v1/speech/synthesise",
        type: "post",
        // contentType: "multipart/form-data; boundary=<calculated when request is sent>",
        data:formData,//JSON.stringify(arr),
        contentType : false,
        processData : false,
        // data:new FormData(message :"11111111112222"),
        headers: {
        "Authorization":token,
        },
        success: function (result) {
        }
    })

ajax+controller

 

 

 $.ajax({
            url: "/Alarm/GetAlarmRecords?isResType=1&resType=" + $("#resType").find('option:selected').val() +"&username=" + $("#alarmTxt1").val() + "&date=" + $("#ChangeTime").val() + "&dateEnd=" + $("#ChangeTime2").val() + "&ischeckdate=" + $("#ischeckdate").prop("checked") + "&alarmClassifyID=" + $("#classifyName").find('option:selected').val() + "&alermtype=" + $("#allarg1").find('option:selected').val() + "&isRespond=" + $("#isRespond").find('option:selected').val(),
            dataType: "json",
            async: true, //异步,否则加载中不执行
            beforeSend: function () {
                $.loading(true)
            },
            success: function (data) {
               ....

                $("#page3").paging({ //分页放到success里,否则分页参数未加载出来
                    pageNum: 1, // 當前頁面
                    totalNum: currentdata.pageCount, // 總頁码
                    totalList: currentdata.totalCount, // 記錄總數量
                    callback: function (num) { //回调函數
                        $.ajax({
                            url: "/Alarm/GetAlarmRecords?isResType=1&resType=" + $("#resType").find('option:selected').val() + "&username=" + $("#alarmTxt1").val() + "&date=" + $("#ChangeTime").val() + "&dateEnd=" + $("#ChangeTime2").val() + "&ischeckdate=" + $("#ischeckdate").prop("checked") + "&alarmClassifyID=" + $("#classifyName").find('option:selected').val() + "&alermtype=" + $("#allarg1").find('option:selected').val() + "&isRespond=" + $("#isRespond").find('option:selected').val() + "&index=" + num,
                            dataType: "json",
                            async: true,
                            beforeSend: function () {
                                $.loading(true)
                            },
                            success: function (data) {
                  ....
                          
                            },
                            complete: function () {
                                $.loading(false)
                            },
                        })
                        page = num;
                    }
                });
            },
            complete: function () {
                $.loading(false)
            },
        });

 

posted @ 2022-08-25 14:52  我の前端日记  阅读(52)  评论(0编辑  收藏  举报
Copyright © 2021 LinCangHai
Powered by .NET 5.0 on Kubernetes