The premise is that the function and the corresponding view route are already configured, and then the form is:
<formID= "Smsform"Method= "POST"class= "a">{% Csrf_token%}<Divclass=""> <inputclass=""name= "Name"ID= "Name"type= "text"placeholder= "Please enter user name"> </Div> <Divclass= "Form-group"> <inputtype= "text"onfocus= "(this.type= ' time ')"ID= "Pick_time"name= "Time"placeholder= "Please enter Time" > </Div> <Divclass= "Form-group"> <inputclass=""name= "ADDR1"ID= "ADDR1"type= "text"placeholder= "Please enter address 1"> </Div> <Divclass= "Form-group"> <inputclass=""name= "ADDR2"ID= "ADDR2"type= "text"placeholder= "Please enter Address 2"> </Div> <Divclass= "Form-group"> <inputclass= "Form-control"name= "Tel"ID= "Tel"type= "text"placeholder= "Please enter the phone"> </Div> <inputclass= "B"type= "button"value= "Preview SMS"onclick= "send_sms (' Check ')"/> <inputclass= "B"type= "button"value= "Send SMS"onclick= "send_sms (' send ')"/> </form>
<Scriptsrc= "/static/js/jquery.min.js"></Script><Script> $('#pick_time'). Blur (function(){ varobj= $( This); if(!Obj.val ()) {Obj.prop ('type','text'); }});functionsend_sms (work_operation) {varData={}; data['Status'] =work_operation; varparams= $('#SmsForm'). Serializearray (); for(xinchparams) {Data[params[x].name]=Params[x].value; } $.ajax ({type:"POST", URL:"{% url ' managing:get_sms_message '%}", Data:data, DataType:"JSON", Success:function(response) {document.getElementById ("Get_sms_message"). Textcontent=Response.message; }, Error:function(RS, E) {alert (rs.responsetext); } });}</Script>
First, generate a data dictionary, and then pass the parameter as a window sill into the dictionary, and then the data of the form into a params variable inside, this method I also found on the internet, the approximate meaning should be the form data in the form of an array, and then is to traverse the params variable, In order to pass the form data into data, and then put data into the data of the post, which is the view to receive the information, according to the different incoming parameters to write the test function and send function.
How to get form parameters when using Ajax in Django (button carrying parameters)