form 上傳圖片不刷新
阿新 • • 發佈:2018-12-13
otc mage author 技術 func ESS alt com als
<!-- /** * @Author: cyany_blue * @Date: 2018-12-12 21:24:54 * @Last Modified by: cyany_blue * @Last Modified time: 2018-12-12 22:09:15 */ --> <!DOCTYPE html> <html lang="en"> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <body> <form onsubmit="return false" enctype="multipart/form-data" method="post" name="fileinfo" id="form1"> //阻止默認刷新retrue false; <input type="file" name="file[]" multiple="true"> 單文件上傳file,多文件上傳file[]接收 <input type="submit" value="submit" class="sumbit1"> </form> </body> <script> $(function(){ $(".sumbit1").click(function(ev){ var formData = new FormData(document.querySelector("#form1")); console.log(formData) $.ajax({ url:‘upload.php‘, type:‘post‘, data:formData, contentType: false, //很重要 processData:false,//很重要,不然會報非法錯誤。。。 success:function(res){ console.log(res); } }); // ev.preventDefault(); }); }) </script> </html>
<?php
/**
* @Author: cyany_blue
* @Date: 2018-12-12 21:20:53
* @Last Modified by: cyany_blue
* @Last Modified time: 2018-12-12 21:43:43
*/
$uploads = $_FILES["file"];
var_dump($uploads);
?>
form 上傳圖片不刷新