js点击下载按钮下载返回的文件

通过ajax请求获取返回的文件url

1、html

<button type="button" class="btn btn-primary" id="download_search">下载</button>

2、js

$(function(){
	//点击下载按钮事件
	$('#download_search').click(function() {
		$.ajax({
			type: "get",
			async: false,
			url: '/list',
			data: {
				xx: yy
			},
			success: function(result) { // result为返回的数据 
				location.href = result.url;
			}
		});
	});                                                                      
});

猜你喜欢

转载自blog.csdn.net/LLL_liuhui/article/details/84141666