How to get form parameters when using Ajax in Django (button carrying parameters)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.