完美定义点击按钮触发函数提交数据【ajax】
1.html代码
<button class="layui-btn layui-btn-small" style="height: 30px;line-height:1.6em;" title="导出csv" onclick="exportCSV()"> <i class="layui-icon" style="line-height:32px;font-size: 14px;">导出csv</i> </button>
2.javascript代码
function exportCSV (argument) { //导出csv var url = "xxx"; $.ajax({ url: url, type: "POST", //data: $(‘#layui-form‘).serialize(), data: { "filter_platform":$("#filter_platform").val(), "filter_accoount":$("#filter_accoount").val(), "filter_project":$("#filter_project").val(), "export_cvs":"export_cvs" }, beforeSend: function (xhr,settings) { xhr.setRequestHeader("X-CSRFtoken",$.cookie("csrftoken")); layer.msg(‘csv生成中,请等待......‘, {icon: 4,time:600000}); }, success: function (data) { if (data.code == 0){ window.open("/static/xxx/download/" + data.file_name); layer.alert(data.msg, {icon: 6}); } else { layer.alert(data.msg, {icon: 7}); } }, complete: function () { console.info("生成csv数据执行完成......"); }, error: function (data) { console.info("生成csv数据执行出错......"); } }); }
相关推荐
zhjn0 2020-11-24
夜斗不是神 2020-11-17
学习web前端 2020-11-09
waiwaiLILI 2020-11-03
raidtest 2020-10-09
myccc 2020-09-24
jzlixiao 2020-09-15
guicaizhou 2020-09-15
digwtx 2020-09-14
大秦铁骑 2020-08-19
thatway 2020-08-19
lovecodeblog 2020-08-19
codetyper 2020-08-16
comwayLi 2020-08-16
MongoDB数据库 2020-08-16
cjsyrwt 2020-08-14
Tristahong 2020-08-05
csuzxm000 2020-08-02
前端开发Kingcean 2020-07-30