When user asks a question on my form and needs to upload a image they can by clicking on button and opens a bootstrap modal. When the user ask a question that question has its own id.
I would like to know how to combine these to on my ajax code below
Question: How to combine question code val with the form upload?
I would like to know how to combine these to on my ajax code below
Code:
var form_upload = new FormData($('#form-upload')[0]);
var question_code = $('#form-ask #question_code').val()Question: How to combine question code val with the form upload?
Code:
$('input[id=\'file\']').on('change', function(e) {
if (typeof timer != 'undefined') {
clearInterval(timer);
}
timer = setInterval(function() {
if ($('input[id=\'file\']').val() != '') {
clearInterval(timer);
// Form-upload is in bootstrap modal
var form_upload = new FormData($('#form-upload')[0]);
var question_code = $('#form-ask #question_code').val()
$.ajax({
url: "<?php echo base_url('question/ask/upload');?>",
type: 'post',
dataType: 'json',
data: form_upload,
cache: false,
contentType: false,
processData: false,
success: function(json) {
if (json['error']) {
alert(json['error']);
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
}, 500);
});