12.Django and Ajax

Source: Internet
Author: User

Django and Ajax

01.AJAX Introduction:
AJAX (Asynchronous JavaScript and XML) is translated into Chinese as "Asynchronous JavaScript and XML."

* Synchronous Interaction: After a client makes a request, it needs to wait for the server response to complete before issuing a second request
* Asynchronous Interaction: After a client makes a request, it can issue a second request without waiting for the server response to end
*ajax In addition to the characteristics of async, there is another is: Browser page local Refresh

Advantages:
Ajax uses JavaScript technology to send asynchronous requests to the server
Ajax does not need to refresh the entire page


02.ajax Sending JSON data

1 //Send JSON data2 $ ('. btn '). Click (function () {3 4 $.ajax ({5 URL: "",6 type: "Post",7 contentType: "Application/json",//The default contentType is urlencoded8 data:JSON.stringify ({//equivalent to Python in Json.dumps9 A:1,Ten B:2 One }), A success:function (data) { -  - } the }) -})

03.ajax Uploading Files

1 <form>2User name<inputtype= "text"ID= "User">3Avatar<inputtype= "File"ID= "Avatar">4 <inputtype= "button"ID= "Ajax-submit"value= "Ajax-submit">5 </form>6 7 <Script>8 $("#ajax-submit"). Click (function(){9 //get file Fixed formatTen varFormdata=NewFormData (); One Formdata.append ("User",$("#user"). Val ()); A Formdata.append ("avatar_img",$("#avatar")[0].files[0]);//JS gets the file first converted to DOM object, and then through. Files[0] Get - $.ajax ({ -  the URL:"", - Type:"Post", - Data:formdata, - //upload the file must write these two lines!!!  + ProcessData:false , //do not process data - ContentType:false, //do not set content type +  A Success:function(data) { at console.log (data) - } - }) - }) - </Script>

12.Django and Ajax

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.