Django and Ajax Tutorials (iii)

Source: Internet
Author: User
Tags: Web python django Ajax Casual original address: [Url]http://www.willarson.com/blog/?p=38[/url] Part III: Django and Prototype:ajax Request (asymmetric mode send data)Another common feature of Ajax is the ability to send data to the server without forcing users to reload their entire page. In the third section of the Django and Ajax tutorials We will send the contents of the Django build form to the server. (The difference between request and Upater is that the Requset object does not need to be answered by the server, which is explained in more depth below.) You can get the source code for the example in this section from here. Ajax Request syntax and purposeAjax.requst is responsible for one-way communication from the Web page to the server. It's probably like a web page saying "Hi, this guy created an account, I already know what to do, so don't bother to give me the instructions", or maybe like a webpage that says "Server My man, you had a new comment to hold onto until someone C An approve it.     (You have a new comment that needs to be kept until someone approves it--that's not quite clear.) "When you want to use Ajax.request to get some HTML from the server to populate the Div, or get any kind of response from the server, it's useless and you won't get anything. Ajax.request syntax is: New Ajax.request (' url/to/send/to ', config) url Ajax Updater ... var post = ' id= ' + ID;
New Ajax.request (' category/remove/', {asynchronous:true, method: ' Post ', postbody:post});
New Ajax.request (' Category/add ', {asynchronous:true, Parameters:Form.serialize (Form)}); Prototype Form using Ajax.request in a Django applicationAt the beginning of the article we talked about creating a page with a simple form that will be sent to the server when we press the Submit button. After sending, we will use the library to reset the form. Javascript Modify urls.pyajaxapp/urls.pyajaxapp/urls.py views We need to add two functions to the view---。     We also write the form and view together (it is best to separate the model from the view in a large project). The model will have two fields, one.     We will pass the function to render the "variable passed to it." We also need to create an instance, or perhaps update an existing instance with a new value.     Fortunately, it's easy to get key values from a form. Note that because we receive an instance of a form that has been created by using data to be converted to. As simple as this: def send (Request):
Post = Request. POST
    form = Commentform (POST) Form_for_model Form.save () model views.py    Our example only requires a simple template that will be used to display the commit processing that was created earlier to override the form's default. This template is extended from the default method that we created in the first section of the tutorial. This form is serialized because we have returned a convenient method in the call to the library. You can use the syntax of the first example near the beginning of the article to create your own arbitrary, template creation, and the encoding of the view: everything is done. Python manage.py runserver scriptaculous<span times= "" new= "" roman "; =" mso-ansi-language:= "" en-us;= "" mso-fareast-language:= "zh-cn;=" "mso-bidi-language:=" "ar-sa;=" "mso-bidi-font-size:=" "11.0pt;=" " mso-font-kerning:= "" 1.0pt "=" style= "padding:0px; margin:0px; font-size:10.5pt; " > To drag and drop the list.
Related Article

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.