Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the code for JQuery asynchronous post uploading form data

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today Xiaobian to share with you about JQuery asynchronous post upload form data code how to write the relevant knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you have something to gain after reading this article, let's take a look at it.

HTML Code:

Jquery Code:

$("# form") .submit (function (e) {e.preventDefault (); / / prevent form refresh, or add return false at the end of the function Var formData = new FormData ($("# form") [0]) / / the parameter for instantiation of formData object must be DOM, plus [0] jquery object is converted to dom object $.ajax ({url: "http://0.0.0.1/api", / * interface domain name address * / type:'post', data: formData, contentType: false, processData: false, / / if it is a cross-domain request Please add the following four lines / / xhrFields: {/ / withCredentials: true / /}, / / crossDomain: true, success:function (res) {console.log (res) / / judge the data transmission status based on the returned data in JSON format. There is no standard depending on what data is returned by the backend. / / if (res.data ["code"] = = "succ") {/ / alert ("success"); / /} else if (res.data ["code"] = = "err") {/ / alert ("failure"); / /} else {/ / console.log (res) / /}}, error:function (error) {console.log (error);})})

Backend Flask data processing:

@ 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": "processed"} return jsonify (dict) above is all the content of the article "how to write the code for JQuery asynchronous post to upload form data" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report