Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax architecture in Django application

I am trying to find the optimal architecture for an ajax-heavy Django application I'm currently building. I'd like to keep a consistent way of doing forms, validation, fetching data, JSON message format but find it exceedingly hard to find a solution that can be used consistently.

Can someone point me in the right direction or share their view on best practice?

like image 433
Jonas K Avatar asked Dec 02 '09 13:12

Jonas K


People also ask

What is AJAX used for in Django?

Ajax essentially is a combination of technologies that are integrated together to reduce the number of page loads. We generally use Ajax to ease end-user experience. Using Ajax in Django can be done by directly using an Ajax library like JQuery or others.

What is AJAX explain its architecture?

AJAX = Asynchronous JavaScript and XML. AJAX is a technique for creating fast and dynamic web pages. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.

How send data from AJAX to Django?

To send and receive data to and from a web server, AJAX uses the following steps: Create an XMLHttpRequest object. Use the XMLHttpRequest object to exchange data asynchronously between the client and the server. Use JavaScript and the DOM to process the data.

How does AJAX save data in Django?

Create the AJAX View First, we set up an if statement to check if the request is a POST request. If it is a POST request, we pass the posted data stored in request. POST to the form—this is known as binding a form to a dataset. Next, we check the form to see if the submitted data is valid.


1 Answers

I make everything as normal views which display normally in the browser. That includes all the replies to AJAX requests (sub pages).

When I want to make bits of the site more dynamic I then use jQuery to do the AJAX, or in this case AJAH and just load the contents of one of the divs in the sub page into the requesting page.

This technique works really well - it is very easy to debug the sub pages as they are just normal pages, and jQuery makes your life very easy using these as part of an AJA[XH]ed page.

like image 52
Nick Craig-Wood Avatar answered Oct 22 '22 20:10

Nick Craig-Wood