5
I have a code that works perfectly for sending files without refresh using PHP and jQuery and I have another code that works without refresh also but for inserting the data in DB. I can’t put the two codes together.
What I want is basically to send the data and upload a file using the same form and a single request. I believe the problem is in the attribute "date:"
jQuery Code - Send Inputs:
$( "#create" ).on( "click", function() {
formId = $(this).closest( ".form" ).attr("id");
formArray = $("#" + formId).serializeArray();
$.ajax({
type: 'POST', url: 'ajax.php',
data: { type: 'create', formArray: formArray },
success: function( msg ) {
alert( msg );
window.location.reload();
},
error: function() {
alert('AJAX Error');
}
});
event.preventDefault();
});
jQuery Code - Upload Files:
var form;
$('#fileUpload').change(function (event) {
form = new FormData();
form.append('fileUpload', event.target.files[0]);
});
$( "#teste" ).on( "click", function() {
$.ajax({
type: 'POST', url: 'ajax.php',
processData: false,
contentType: false,
data: form,
success: function( msg ) {
alert( msg );
},
error: function() {
alert('AJAX Error');
}
});
event.preventDefault();
});
And which element receives the click?
#teste
or#create
? Or both and must do the same?– Sergio
In fact it would be the only #create, the #test was created only for test purposes same, I wanted to join the two.
– tassiodias