網站首頁 編程語言 正文
HTML代碼:
jquery代碼:
$("#form").submit(function (e) {? ? ? e.preventDefault();//阻止表單刷新,也可以函數最后加上 return false; ? ? var formData = new FormData($("#form")[0]);//formData對象實例化的參數必須為DOM,加上[0]jquery對象轉為dom對象 ? ? $.ajax({ ? ? ? ? url:"http://0.0.0.1/api", /*接口域名地址*/ ? ? ? ? type:'post', ? ? ? ? data: formData, ? ? ? ? contentType: false, ? ? ? ? processData: false, ? ? ? ? //如果是跨域請求,請加上下面四行 ? ? ? ? //xhrFields: { ? ? ? ? // ? ?withCredentials: true ? ? ? ? //}, ? ? ? ? //crossDomain: true, ? ? ? ? success:function(res){ ? ? ? ? ? ? console.log(res); ? ? ? ? ? ? //根據返回的JSON格式數據判斷數據傳輸狀態,這個看后端返回的啥數據,沒有標準。 ? ? ? ? ? ? // if(res.data["code"]=="succ"){ ? ? ? ? ? ? // ? ? alert('成功'); ? ? ? ? ? ? // }else if(res.data["code"]=="err"){ ? ? ? ? ? ? // ? ? alert('失敗'); ? ? ? ? ? ? // }else{ ? ? ? ? ? ? // ? ? console.log(res); ? ? ? ? ? ? // } ? ? ? ? }, ? ? ? ? error:function(error){ ? ? ? ? ? ? console.log(error); ? ? ? ? } ? ? }) });
后端Flask數據處理:
@app.route('/api',methods=['GET','POST'])? def api(): ? ? # for item in request.form: ? ? # ? ? print(item) ? ? d1 = request.form.get("l1") ? ? d2 = request.form.get("l2") ? ? d3 = request.form.get("l3") ? ? file = request.files.get('file')? ? ? print(file) ??? ?dict = {"code":"200","data":"處理完畢"} ? ? return jsonify(dict)
原文鏈接:https://blog.csdn.net/Crayonxin2000/article/details/122615939
相關推薦
- 2022-06-16 golang?gorm更新日志執行SQL示例詳解_Golang
- 2022-04-01 Python?eval()?函數看這一篇就夠了_python
- 2022-06-25 React?Hooks與setInterval的踩坑問題小結_React
- 2022-03-26 Postman配置多環境請求地址的實現_相關技巧
- 2022-03-17 淺析.netcore中的Configuration具體使用_實用技巧
- 2022-12-22 Flutter?Widget?之StatefulBuilder構建方法詳解_Android
- 2022-09-30 Python?添加命令行參數步驟_python
- 2024-02-26 Cannot execute binary file 之原因
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支