0

I made a website in python using Django. My site allows you to control lights while indicating if the light is on or not. I'm looking for a solution that could make a simple request with data to the server and send data back to the client without updating the entire page but only a part of it.

My ideal would be for the client to make a request to the server with identification data. Then, the server returns the updated data that the user is allowed to have.

Is that possible to make a JavaScript to do that ? And the server, how it can return data to the client ?

Axok
  • 25
  • 4
  • Possible duplicate of [Refresh
    element generated by a django template](https://stackoverflow.com/questions/3583534/refresh-div-element-generated-by-a-django-template)
    – iScripters Sep 22 '19 at 10:57

1 Answers1

0

You can Use jquery AJAX for send request and get a response and Update an element or part of the page you can read more about it in :

W3schools

or :

jquery.com

AJAX function I use for PHP project:(Just for example)

$.ajax({
        type: "POST",
        url: Url,
        data: InfoData, // data if you want to send for example InfoData={dataName: variable} or you can set this = '' if you don't want to send data
        datatype: "html",
        success: function(result) {
            console.log(result);
        }
    });
Amir Hossein
  • 916
  • 2
  • 13
  • 38
  • Thanks but how i can launch this code from a button for exemple ? Can i put that directly in my HTML code between – Axok Sep 22 '19 at 18:18
  • you can launch it with javascript or jquery event like onclick="yourFunction()" or $("#your-button").click(); – Amir Hossein Sep 23 '19 at 05:33
  • https://www.w3schools.com/jquery/event_click.asp or https://www.w3schools.com/jsref/event_onclick.asp you can read these links and know how to launch it – Amir Hossein Sep 23 '19 at 05:34
  • https://pastebin.com/wzzYAmAP : Here is my code, but it does not work with a file name "demo_test.txt" as my page named "index.html"... What's wrong ? – Axok Sep 23 '19 at 19:14
  • I'm sorry, don't worry, i don't have any more problem thanks you – Axok Sep 23 '19 at 19:27