test5.htmlphp
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <script> $(document).ready(function(){ $("#ajax-submit").click(function(){ var formdata=new FormData(); formdata.append("user",$("#user").val()); formdata.append("avatar_img",$("#avatar")[0].files[0]); $.ajax({ url:"phpinfo.php", type:"post", data:formdata, processData: false , // 不處理數據 contentType: false, // 不設置內容類型 success:function(data){ console.log(data) } }) }) }) </script> </head> <body> <form> 用戶名 <input type="text" id="user"> 頭像 <input type="file" id="avatar"> <input type="button" id="ajax-submit" value="ajax-submit"> </form> </body> </html>
phpinfo.phphtml
<?php header("Content-type: text/html; charset=utf-8"); print_r($_POST); print_r($_GET); print_r($_FILES); exit;
報文:jquery