POST發起下載請求

weixin_34208283發表於2018-07-21

GET方式請求下載時總是要對中文進行編碼,然後後臺再解碼比較繁瑣,POST方式主要通過js構建表單屬性

download:function () {
            //下載 post方式
            $("#downloadform").remove();
            var form=$("<form>");
            form.attr("id","downloadform");
            form.attr("style","display:none");
            form.attr("target","");
            form.attr("method","post");
            form.attr("action", "${base}/smarteye/downloadCSV.htm");
            var input1=$("<input>");
            input1.attr("type","hidden");
            input1.attr("name","userId");
            input1.attr("value",$('#userId').val());
            form.append(input1);
            var input2=$("<input>");
            input2.attr("type","hidden");
            input2.attr("name","userName");
            input2.attr("value",$('#userName').val());
            form.append(input2);
            var input3=$("<input>");
            input3.attr("type","hidden");
            input3.attr("name","roleName");
            input3.attr("value",$('#roleName').val());
            form.append(input3);
            $("body").append(form);

            form.submit();


        }

相關文章