简体   繁体   中英

the page freeze when uploading file image using ajax

I created a ajax function for uploading file images, everything works except there's an ugly part where the page freezed at the process (ajax file image processing submission), any ideas, help, suggestions, clues? below is my code reference.

$("#form_image_file_submit").submit(function(e){
    var this_current = $(this);
    var formData = new FormData(this_current[0]);
    $.ajax({
     url : this_current.attr("action"),
     data: formData,
     type: 'post',
     cache: false,
     async: false,
     complete: function(data){
        alert(data);
    }
});

You have async: false . Change it to true

Use async:true or remove it.

async (default: true) Type: Boolean By default, all requests are sent asynchronously (ie this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success().

Ajax Docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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