$(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("