Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a function which is saving some data by ajax and return a response.
This is my success function
C#
success: function (response) {
               if (response.d != "0") {

                   function clickCall(callback) {
                       $("#startUploadbuscase").click(); //start to upload files//
                       callback();
                       return true;
                   }
                   function redirectToAnother() {
                       /*if (submitOrDraft == "draft") {
                       window.location = "businesscaselist.aspx?opn=0&bcse=" + response.d;
                       }
                       else if (submitOrDraft == "submit") {
                       window.location = "businesscaselist.aspx?opn=1&bcse=" + response.d;
                       }*/
                       alert('done');
                   }

                   clickCall(redirectToAnother);


               }
               else {
                   $("#divToShowOnSavingFinalBuscase").hide();
                   alert("Error occurred while processing Business Case");
               }
           },


Clickcall() should call redirecttoanother() after its execution finished as I've given callback().
The $("#startUploadbuscase").click() is starting the upload of multifile uploader as below.


C#
$( document ).ready(function() {
function initializeUploader(type,foldername) {
    $("#startUploadbuscase").unbind("click"); //unbind click to create a new

    var uploadObj = $("#divfileuploaderbuscase").uploadFile({
        url: "uploadHandler.ashx?type=" + type + "&fname=" + foldername,
        method: "POST", // Upload Form method type POST or GET.
        enctype: "multipart/form-data", // Upload Form enctype.
        returnType: null,
        allowedTypes: "jpg,png,gif,doc,docx,pdf,jpeg,rar,xls,xlsx", // List of comma separated file extensions: Default is "*". Example: "jpg,png,gif"
        fileName: "file", // Name of the file input field. Default is file
        //formData: { "name": "Ravi", "age": 31 },
        formData: {},
        dynamicFormData: function () { // To provide form data dynamically
            return {};
        },
        maxFileSize: 5 * 1024 * 1024, // Allowed Maximum file Size in bytes.(here is 5mb)
        //maxFileCount: -1, // Allowed Maximum number of files to be uploaded
        multiple: true, // If it is set to true, multiple file selection is allowed.
        dragDrop: true, // Drag drop is enabled if it is set to true
        autoSubmit: false, // If it is set to true, files are uploaded automatically. Otherwise you need to call .startUpload function. Default istrue
        showCancel: true,
        showAbort: true,
        showDone: false,
        showDelete: false,
        showError: true,
        showStatusAfterSuccess: true,
        showStatusAfterError: true,
        showFileCounter: true,
        fileCounterStyle: "). ",
        showProgress: true, //--false--
        nestedForms: true,
        showDownload: false,
        onSuccess: function (files, response, xhr, pd) { },
        onError: function (files, status, message, pd) { },
        onCancel: function (files, pd) { },
        downloadCallback: false,
        deleteCallback: false,
        afterUploadAll: function () {

        },
        uploadButtonClass: "ajax-file-upload",
        dragDropStr: "<span><b>Drag &amp; Drop Files</b></span>",
        abortStr: "Abort",
        cancelStr: "Cancel",
        deletelStr: "Delete",
        doneStr: "Done",
        multiDragErrorStr: "Multiple File Drag &amp; Drop is not allowed.",
        extErrorStr: "is not allowed. Allowed extensions: ",
        sizeErrorStr: "is not allowed. Allowed Max size: ",
        uploadErrorStr: "Upload is not allowed",
        maxFileCountErrorStr: " is not allowed. Maximum allowed files are:",
        downloadStr: "Download",
        statusBarWidth: 500,
        dragdropWidth: 500
    });



    $("#startUploadbuscase").click(function () {
        uploadObj.startUpload();

    });
};
});



But problem is filupload doesnot stop executing the second function redirecttoanother(),I mean wheather the file upload is finished or not,the second function fired.So how to sequence it?
Posted
Updated 8-Feb-15 22:06pm
v3

1 solution

You need to call redirectToAnother on 'stop'.

See this link: https://github.com/blueimp/jQuery-File-Upload/wiki/Options#stop[^]
 
Share this answer
 
Comments
souvikcode 9-Feb-15 9:06am    
First of all I'm not using blueimp.But can you please give an example how to implement it?
InbarBarkai 9-Feb-15 9:08am    
What are you using then?
souvikcode 9-Feb-15 10:40am    
http://hayageek.com/docs/jquery-upload-file.php
InbarBarkai 9-Feb-15 23:28pm    
Okay, use the "afterUploadAll" event.
http://hayageek.com/docs/jquery-upload-file.php
souvikcode 10-Feb-15 11:48am    
yes.but redirecttoanother() is in different scope with fileupload initialization.So how can I call the function redirecttoanother() outside its scope?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900