Created
December 5, 2017 21:48
-
-
Save RiFi2k/84457bfc122af9868b97400c49841a94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function( $ ) { | |
'use strict'; | |
// On DOM ready. | |
$(function() { | |
$('#dtk-importer-start').submit(function(e) { | |
e.preventDefault(); | |
var str = $(this).serialize(); | |
var div = $('#dtk-import-reload'); | |
var error = '<span class="ajax-error">Sorry, you broke it</span>'; | |
var total = "<?php echo $total_chunks; ?>"; | |
var size = "<?php echo $total_chunks; ?>"; | |
function processChunk() { | |
if (size <= 0) { | |
return; | |
} | |
$.ajax({ | |
url: ajaxurl, | |
method: 'POST', | |
data: { | |
action: 'dtk_import_chunk', | |
total: total, | |
size: size, | |
data: str | |
}, | |
beforeSend: function() { | |
$('#dtk-import').addClass('dtk-loading'); | |
}, | |
error: function() { | |
div.html(error); | |
}, | |
success: function(data) { | |
div.html(data); | |
}, | |
complete: function() { | |
$('#dtk-import').removeClass('dtk-loading'); | |
size--; | |
processChunk(); | |
} | |
}); | |
} | |
processChunk(); | |
}); | |
}); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment