English 中文(简体)
您是否真的或使用j Query上载,以防止用户在文件上卸载时离开?
原标题:Should you set async true or use jQuery beforeunload to prevent users leaving during a file upload?

如果您使用j Query和Ajax混合体来管理像这样的用户上载表格的头端:

$( form :button ).click(function(){

    var formData = new FormData($("form")[0]);

    $.ajax({
        url:  /upload ,
        type:  POST ,
        xhr: function() {
            myXhr = $.ajaxSettings.xhr();
            if(myXhr.upload){
                myXhr.upload.addEventListener( progress , progressHandlingFunction, false);
            }
            return myXhr;
        },
        data: formData,
        success: function (res) {
            alert("Uploaded");
        },
        cache: false,
        contentType: false,
        processData: false
    });
});

使用<代码>sync:false,阻止所有浏览器移动,直至上载完成或使用某种舱位功能,如上载<,以便通知用户,离开网页将中断上载?

$(window).bind( beforeunload , function(){
    return  If you leave this page, your upload will not complete! Continue? ;
});

在Ajax,只有上载时才能运行功能吗?

最佳回答

在上载程序启动时节省国旗可能更好:

$( form :button ).click(function(){

    var formData = new FormData($("form")[0]);
    var $this = $(this);
    $this.data( uploading , true);

    $.ajax({
       ..., // your attributes
       success: function (res) {
           $this.data( uploading , false);
           alert("Uploaded");
       },
    ... // rest of your code
});

接着,<代码>未上载

$(window).bind( beforeunload , function(){
    if($( form :button ).data( uploading ) === true) {
       return  If you leave this page, your upload will not complete! Continue? ;
    }
});
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签