通过将文件上载到ASHX处理程序来实现SSE(服务器发送的事件)
Implement SSE (Server Sent Events) with File Upload to ASHX Handler
我想实现以下内容:
- 使用Jquery从UI调用ASHX hanlder
- 将文件上载到此ASHX处理程序
- 上传完成后,我想继续从服务器向UI(SSE)发送消息,告诉用户ASHX处理程序中代码的执行状态
我被上面提到的第三点卡住了。
以下是我写的UI代码:
var file = $("input#importFileInputHidden")[0].files[0];
var formData = new FormData();
formData.append('file', file);
importAjaxCall = $.ajax({
xhr: function () {
var xhr = new window.XMLHttpRequest();
$('#progressBar').show();
//Method to show the progress of the file being uploaded
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = Math.round((evt.loaded / evt.total) * 100);
$('#percentageImportComplete').text('' + percentComplete + '%');
$('#importStatus').css('width', percentComplete + '%');
}
}, false);
return xhr;
},
type: 'post',
url: "Handler.ashx",
data: formData,
processData: false,
contentType: false,
success: function (data) {
//Some code to show success status to user
});
如何捕获我从服务器发送的消息?
是否尝试过查看http请求的responseText属性?
success: function () {
console.log(xhr.responseText);
});
相关文章:
- 使用JSP从服务器检索和显示图像
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 客户端服务器REST API captcha实现
- 正在将base64 jpeg从input-type=file上传到服务器
- Webpack开发服务器和React服务器端渲染
- 提示使用服务器端事件处理程序激活JavaScript
- 使用谷歌应用程序脚本将服务器端数据表返回到客户端
- 如何使用Socket.io将命令从客户端发送到服务器
- jQuery blueimp文件上传:将N-1个文件上传到IE中的服务器
- 使用jasmine模拟对服务器的调用
- 如何轻松地将服务器端变量从Java代码转移到客户端代码
- 从客户端获取修改后的对象,并将其与服务器上的原始对象组合
- 通过ajax将坐标传递到php服务器端,并在处理后检索到javascript
- 通过将文件上载到ASHX处理程序来实现SSE(服务器发送的事件)
- SSE(服务器发送的事件)断开连接
- 为什么打开的服务器发送的事件会阻止其他 SSE、POST 或 GET
- SSE客户端在我修改服务器时停止工作(Server Sent Event)
- 服务器端事件(SSE)未到达客户端
- 如何通过单击页面上的按钮触发服务器发送SSE
- 从服务器检索命名为“data:"”以外的SSE的数据