1. 程式人生 > >js點選下載按鈕下載返回的檔案

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;
			}
		});
	});                                                                      
});