1. 程式人生 > >轉載:關於ajax,form表單提交,http請求提交的區別

轉載:關於ajax,form表單提交,http請求提交的區別

https://www.cnblogs.com/lidgblogs/archive/2017/09/01/7403828.html

ajax模仿form上傳:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta 
http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <form id= "uploadForm"> <p>指定檔名: <input id="reportType" type="text" name="filename" value= "1"/></p > <p>上傳檔案: <input type="file" name="file" value=
""/></p> <input type="button" value="上傳" onclick="doUpload()" /> </form> <script src="jquery-1.8.3.min.js"></script> <script> function doUpload() { var formData = new FormData($("#uploadForm")[0]); var reportType = $('#reportType').val(); $.ajax({ url
: 'http://192.168.1.124/creditReoprtImport/import' , type: 'POST', data: {reportType:reportType,formData:formData}, async: false, cache: false, contentType: false, processData: false, success: function (returndata) { alert(returndata); }, error: function (returndata) { alert(returndata); } }); } </script> </body> </html>