javascript - How to pass input value to ajax using FormData? -


i trying upload images using ajax , php , have managed make work level successfully, can't make input's value (id) pass php file.

here's scenario.

form

<form enctype="multipart/form-data" id="myform">         <input type="file" name="images[]" multiple id="image"/> </form> 

button

<button type="button" id="uploadimages" name="thing_id"  value="<?php echo $row['thing_id']; ?>" class="btn btn-primary">save changes </button> 

ajax

    $("#uploadimages").click(function () {         var form = new formdata($('#myform')[0]);          // make ajax call         $.ajax({             url: 'uploadimages.php',             type: 'post',             xhr: function () {                 var myxhr = $.ajaxsettings.xhr();                 if (myxhr.upload) {                     myxhr.upload.addeventlistener('progress', progress, false);                 }                 return myxhr;             },             //add beforesend handler validate or             //beforesend: functionname,             success: function (res) {                 $('#content_here_please').html(res);                 /**/             },             //add error handler when error occurs if want!             //error: errorfunction,             data: form,             cache: false,             contenttype: false,             processdata: false         });     }); 

php

$get_id = $_post['']; // stuck. 

how can pass $row['thing_id'] $get_id variable? can pass using ajax call on success, lose image_id value (i use foreach since may upload multiple files), want handle in same php file.

i didn't include upload script because works unless try make using thing_id.

in ajax code pass data attribute

$.ajax({         url: 'uploadimages.php',         type: 'post',         data:{upid:$("#uploadimages").val(),images:$('#uploadfieldid').val()},         xhr: function () {             var myxhr = $.ajaxsettings.xhr();             if (myxhr.upload) {                 myxhr.upload.addeventlistener('progress', progress, false);             }             return myxhr;         },         //add beforesend handler validate or         //beforesend: functionname,         success: function (res) {             $('#content_here_please').html(res);             /**/         },         //add error handler when error occurs if want!         //error: errorfunction,         cache: false,         contenttype: false,         processdata: false     }); 

then can access upid in php file as,i have made updation can send upload file field value php file. change id matches field , can retrieve field using

$get_id = $_post['upid'];

$image = $_post['images'];


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -