You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.2 KiB
57 lines
2.2 KiB
$(document).ready(function(){
|
|
$('#file_form').submit(function(){
|
|
var fileData = new FormData($(this)[0]);//file (request.FILES)
|
|
var formData = $(this).serialize();// another data (request.POST)
|
|
|
|
//check if country is new
|
|
if ($('#obj_id').val() != '') {
|
|
var url = '/admin/ajax_post_file/'+$('#obj_id').val()+'/';
|
|
}
|
|
else {
|
|
var url = '/admin/ajax_post_file/'
|
|
}
|
|
|
|
$.ajax({
|
|
url: url, //server script to process data
|
|
type: 'POST',
|
|
xhr: function() { // custom xhr
|
|
var myXhr = $.ajaxSettings.xhr();
|
|
if(myXhr.upload){ // check if upload property exists
|
|
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload
|
|
}
|
|
return myXhr;
|
|
},
|
|
//Ajax events
|
|
success: postSuccess,
|
|
error: function(){ alert('error'); },
|
|
// Form data
|
|
data: (formData, fileData),
|
|
//Options to tell JQuery not to process data or worry about content-type
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false
|
|
});//end ajax
|
|
return false;
|
|
});//end submit
|
|
|
|
});//end ready
|
|
|
|
function postSuccess(data, textStatus, jqXHR){
|
|
if (data.indexOf("<form")+1){
|
|
$('#form_body').html(data);
|
|
}
|
|
else
|
|
{
|
|
$('#file_list').html(data);
|
|
$('#close').click();
|
|
}
|
|
}
|
|
function deleteSuccess(data){
|
|
alert(data);
|
|
}
|
|
//function for progress bar
|
|
function progressHandlingFunction(e){
|
|
if(e.lengthComputable){
|
|
$('progress').attr({value:e.loaded,max:e.total});
|
|
}
|
|
}
|
|
|