Hi everyone I have a simple form with input for text and file. I want to type some name in input and add file. Here is my HTML code:
Name: <input type="text" id="name" name="name"><br>
File: <input type="file" id="file" name="file"><br>
<button id="submit">Submit</button>
And this is my simple jQuery code:
$('#submit').click(function() {
var file_data = $('#file').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: 'include/upload_idcard.php',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(result){
alert(result);
}
});
});
And in PHP I take the file and etc. But I want the file and the name(input). How to the and the value in input(name)? Thanks.
I hope it will be helpful to you.
$('#submit').click(function() {
var file_data = $('#file').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
form_data.append('name', $("#name").val());
$.ajax({
url: 'include/upload_idcard.php',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(result){
alert(result);
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With