In the middle of development, I decided to switch to server-side rendering for better control, among other benefits . My web application is completely AJAX-based, doesn't redirect URLs, so the idea here is a website that builds itself
I just couldn't figure out how to properly send javascript events / functions along with the html string, or would all the necessary javascript always be preloaded into static files?
Suppose a customer clicks the open table preview button
The server will fulfill the request, build the html table and send it back, but this table also needs triggers and javascript functions to work correctly, how are they sent, received and executed?
There are several articles that mention that not using eval () in Javascript, is there a way around this? I do not want to preload unnecessary events for elements that do not yet exist.
Python server and client - Javascript / JQuery
Theoretical example:
Javascript client base:
$("body").on("click", "#open_table", function() { $.getJSON('/get_table', function(response){ $("#table_div").append(response.html); eval(response.javascript());
Python server (views.py):
def get_table(request): data = {}
It is worth noting that my question comes from an experimental / educational perspective
source share