jquery - How to fetch data from ajax in php -
i passing image form php page using ajax. problem data not getting fetched , giving blank output. following code:
test.php
<!-- taken http://stackoverflow.com/questions/24446281/passing-image-using-ajax-to-php --> <form name="saveimg" enctype="multipart/form-data" id="saveimg"> <input type="file" name="imgvid" id="imgvid"> <button name="submit" id="submit">upload</button> <img src="skin/images/process.gif" id="procimg" height="32" width="auto" style="display:none;" /> </form> <div id="msg"></div> <!--jquery--> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> document.getelementbyid("submit").addeventlistener("click", function(event){ event.preventdefault(); saveimgfunc(); }); function saveimgfunc(){ var form = new formdata(document.getelementbyid('saveimg')); var file = document.getelementbyid('imgvid').files[0]; if (file) { form.append('imgvid', file); } $.ajax({ type : 'post', url : 'core/img.php', data : form, cache : false, contenttype : false, processdata : false }).success(function(data){ console.log(data); }); } img.php
<?php if(isset($_post['submit'])){ echo "data can fetched here"; } ?> kindly me issue. in advance.
change this:
if(isset($_post['submit'])){ to this:
if(isset($_post['imgvid'])){ because not posting 'submit' php. code of line
data : form, has this:
form.append('imgvid', file);
Comments
Post a Comment