vs2017 浏览器关闭、js 代码 导致 自动退出调试状态,中断调试

在 vs2017 的 工具->选项  web项目 项 取消勾选  浏览器窗口关闭时停止调试器

而我在使用 wangEditor 富文本编辑器时,使用自定义上传图片的方法,由于 勾选 浏览器窗口关闭时停止调试器 这个选项,导致请求上传图片 的 Controller 时就断开调试

js代码:

editor.customConfig.customUploadImg = function (files, insert) {
                // files 是 input 中选中的文档列表
                // insert 是获取图片 url 后,插入到编辑器的方法
                var uploadData = new FormData();
                for (var i = 0; i < files.length; i++) {
                    uploadData.append(files[i].name, files[i]);
                }


                $.ajax({
                    type: "POST",
                    url: "Upload",
                    cache: false,
                    data: uploadData,
                    processData: false, // 不做参数化处理
                    contentType: false,
                    async: false,
                    success: function (response) {
                        //alert(response);
                        console.log('success=>' + response.data);
                        for (var i = 0; i < response.data.length; i++) {
                            insert(response.data[i]);
                            console.log('insert url =>' + response.data[i]);
                        }
                    },
                    failure: function (response) {
                        //alert(response);
                        console.log('fail=>' + response.responseText);
                    },
                    complete: function (response) {
                        //alert(response);
                        console.log(response);
                    }
                });
            }

后端代码:

/// <summary>
        /// 图片上传
        /// 注入 IHostingEnvironment
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Upload([FromServices] IHostingEnvironment hostingEnvironment)
        {
            var file = Request.Form.Files[0];
            string webRootPath = hostingEnvironment.WebRootPath;// "\\wwwroot";
            var fileUrl = string.Empty;
            var filePath = string.Empty;

            if (file?.Length > 0)
            {
                // 文件名
                var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + Guid.NewGuid().ToString() + ".jpg";
                // 存放路径
                fileUrl = @"\upload\images";

                if (!Directory.Exists(webRootPath + fileUrl))
                {
                    Directory.CreateDirectory(webRootPath + fileUrl);
                }

                filePath = Path.Combine(fileUrl, fileName);

                using (var stream = new FileStream(webRootPath + filePath, FileMode.CreateNew))
                {
                    await file.CopyToAsync(stream);
                }
            }

            JObject jObject = new JObject();
            jObject.Add("errno", 0);
            jObject.Add("data", new JArray("https://localhost:44381" + filePath));

            return Json(jObject);
}

对于上面代码遇到的 调试断开问题 ,同样也是 取消勾选 浏览器窗口关闭时停止调试器 这个项就能解决

但是 为什么会这样,还没想明白,有路过的大神知道,望能留下宝贵的意见,不胜感激

猜你喜欢

转载自blog.csdn.net/qq1326702940/article/details/82845429