Download file from Ajax (sort of)

前端 未结 4 840
梦如初夏
梦如初夏 2021-01-03 08:11

I have this ajax call in my GSP:

$.ajax({
    url: \'${request.contextPath + \'/Ticket/passAll\'}\',
    type: \'POST\',
    data: data,
    success: functio         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 08:46

    I guess the url property should be fixed as your quotes are colliding.

    Try with:

    $.ajax({
        url: "${request.contextPath}/Ticket/passAll",
        type: 'POST',
        data: aoData,
        dataType: 'text',
        success: function(result) {
            var uri = 'data:application/csv;charset=UTF-8,' + encodeURIComponent(result);
            window.open(uri, 'tiketi.csv');
        }
    });
    

提交回复
热议问题