I attached JS and index.php file. This code not working for image, but for type text it is working properly. I have searched very much but not getting how can upload image by jQuery.
index.php file:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title><?= TITLE . ' | ' . ucfirst($page); ?></title> <!-- Tell the brow form_groupser to be responsive to screen width --> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> <?php include('inc/css-inc.php'); ?> </head> <body> <div class="row form_group"> <div for="inputName" class="col-sm-2 control-div">Image A. </div> <div class="col-sm-4"> <input type="file" class="form-control" id="qimage" name="imga" onchange="un(this.value)"> </div> <button type="button" onClick="return savequestion()" id="savequestion" class="btn btn-info pull-right"><?= $act; ?></button><!--</form>--> <!-- jQuery 2.1.4 --> <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script> <!-- Bootstrap 3.3.5 --> <script src="bootstrap/js/bootstrap.min.js"></script> </body> </html> Js file
$('#savequestion').click(function () { var qimage1 = $('#qimage').prop('files')[0]; var form_data = new FormData(); form_data.append('qimage', qimage1); form_data.append('mod', mod); form_data.append('req', req); $.ajax({ url: 'common_process.php', dataType: 'text', cache: false, contentType: false, processData: false, data: form_data, type: 'POST', success: function (data) { alert(data); } }); });