• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Combine input val ajax from two forms.

#1
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

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);
});
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
Code:
form_upload.append( 'fieldname', question_code );
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.