页面发送请求并且页面停止加载后的事件

我正在提交一个向后端发送请求的表单,C# 操作。后端生成一个pdf文件并发回浏览器下载。我如何捕捉这个事件?我只是想在从服务器发送 pdf 时向用户显示一条消息。我不能使用 ajax,因为我正在通过表单发送请求,并且我希望响应是附件。


        public ActionResult ConvertHTMLtoPDF(string htmltoPDfFullUrl)

        {

            Byte[] res = null;

            using (MemoryStream ms = new MemoryStream())

            {

                // not important logic


            }


            var stream = new MemoryStream(res);


            return new FileStreamResult(stream, "application/pdf")

            {

                FileDownloadName = "some name.pdf"

            };


        }

$(document).on('click', ".formSubmitDiv", function () {

    formSubmit();


})

function formSubmit() {

    $('#htmltoPDfFullUrl').val(fullHTMLLIVE);


    document.getElementById('beginConvertHTMLtoPDF').submit();

}

@using (Html.BeginForm("ConvertHTMLtoPDF", "Home", FormMethod.Post, new { id = "beginConvertHTMLtoPDF" }))

{

    <input type="hidden" name="htmltoPDfFullUrl" id="htmltoPDfFullUrl" />

}


守候你守候我
浏览 139回答 1
1回答

BIG阳

我设法通过从服务器发送一个 cookie 并在客户端上不断检查这个 cookie 来解决这个问题。这就是我发送cookie的方式。Response.Cookies.Add(new HttpCookie(serverCookieResponse + "_CookiePDFResponse", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss:ff")));这就是我检查cookie是否已收到的方式function checkCookie() {&nbsp; &nbsp; let cookieName = $('#serverCookieResponse').val() + "_CookiePDFResponse";&nbsp; &nbsp; var cookieVal = $.cookie(cookieName);&nbsp; &nbsp; if (cookieVal == null || cookieVal === 'undefined') {&nbsp; &nbsp; &nbsp; &nbsp; setTimeout("checkCookie();", 1000);&nbsp; &nbsp; }&nbsp; &nbsp; else {&nbsp; &nbsp; &nbsp; &nbsp; document.cookie = cookieName + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';&nbsp; &nbsp; }}希望这对某人有帮助!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript