繁体   English   中英

如何强制该jquery等待click事件完成?

[英]How can I force this jquery to wait until click event has finished?

我正在使用Ajax文件上载,除了其他外, onClientUploadCompleteAll重载了onClientUploadCompleteAll事件。 我在单击jquery中的“上载”按钮后正在执行导航,并且我想强制该功能等待onuploadcompleteall执行后再执行导航。 目前,它正在导航到下一页,然后运行uploadcompleteall 是否有任何方法可以迫使它等待,或者在onuploadcompleteall事件中获得用户单击的内容?

<asp:AjaxFileUpload ID="AjaxFileUpload1" CssClass="0001.01" runat="server" AllowedFileTypes="jpg,jpeg,png,gif" OnUploadStart="AjaxFileUpload1_UploadStart" OnUploadComplete="AjaxFileUpload1_UploadComplete" OnUploadCompleteAll="AjaxFileUpload1_UploadCompleteAll" OnClientUploadComplete="onClientUploadComplete" OnClientUploadCompleteAll="onClientUploadCompleteAll" OnClientUploadStart="onClientUploadStart"></asp:AjaxFileUpload>

onClientUploadCompleteAll事件:

function onClientUploadCompleteAll(sender, e) { //stuff }

执行点击的文件上传事件:

function handleFileUpload(form) {
    number_of_plugin_instances_having_photos = 0;

    $('.upload-photos').map(function(i, el){
        if($('.uploaded-thumbnail', el).length > 0 || $('.uploaded-thumbnail-title', el).length > 0) {
            number_of_plugin_instances_having_photos++;
        }
    });

    if(number_of_plugin_instances_having_photos == 0) {
        form.submit();
    } else {

        //setTimeout(function(){

            number_of_plugin_instances_callbacks_uploaded = 0;

            $('.upload-photos').map(function(i, el){
                if($('.uploaded-thumbnail', el).length > 0 || $('.uploaded-thumbnail-title', el).length > 0) {
                    $('.ajax__fileupload_uploadbutton', el).trigger('click');
                }
            });
        //}, 1000);

    }
}

调用文件上传事件

$.ajax({
        type: "POST",
        url: loc + "/SubmitSections",
        data: dataValue,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json'
    })
    .done(function (data, status) {
        if (data.d != "success") {
            $("#modal-submitting").modal('hide');
            $(".error_message").text("Unable to submit the data entered.  Please try again.  Additional Details: " + data.d);
            $("#modal-error-occurred").modal('show');
        }
        else {
            handleFileUpload(form, true);

            //NEED TO WAIT BEFORE NAVIGATING OTHERWISE COMPLETE ALL DOES NOT EXECUTE
            document.location = "general-appearance.aspx";
        }
    })
    .fail(function (data, status) {
        if (data.d != "success") {
            $("#modal-submitting").modal('hide');
            $(".error_message").text("Unable to submit the data entered.  Please try again.  Additional Details: " + data.d);
            $("#modal-error-occurred").modal('show');
        }
        else {
            handleFileUpload(form, true);

            //NEED TO WAIT BEFORE NAVIGATING OTHERWISE COMPLETE ALL DOES NOT EXECUTE
            document.location = "general-appearance.aspx";
        }
    });//ajax call end

原来,我可以使用表单操作来获取用户选择导航的位置。 onClientUploadCompleteAll我放置了以下内容:

function onClientUploadCompleteAll(sender, e) {

    //I have more than one photo upload
    number_of_plugin_instances_callbacks_uploaded++;

    if(number_of_plugin_instances_callbacks_uploaded == number_of_plugin_instances_having_photos){
        var first_form = $('form')['0'];
        var nextPage = first_form.action;

        document.location = nextPage;
        //first_form.submit();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM