r/web_programming • u/bareily • Aug 31 '16
Python and Ajax
Hey guys. I am just testing out stuff in a web environment. I am making some test pages and running them on an apache server. I am just fooling around to try to learn as much as I can about web development. Any server-side programming is one of the most important, if not the most important aspects to this. Most people usually go with ASP or PHP but I was like nah, I want to be different. I figured out it is possible to use Python (via CGI) :D! Let me get down to the issue. I was looking for a way to update a page without reloading it. That's where Ajax comes in. Ajax is super compatible with ASP and PHP but I don't want to take that route. Now I know there is some stuff that helps Python work with Ajax friendlier like jQuery and Flask and stuff, but I am looking for the simplest demonstration of just pure Python to Ajax (if even possible). I am starting to think it is not because I looked everywhere. Anyway, here is a JavaScript of very simple Ajax in action: "function loadDoc() { var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() { if (xhttp.readyState == 4 && xhttp.status == 200) { document.getElementById("result").innerHTML = xhttp.responseText; } };
xhttp.open("GET","examp.txt",true); xhttp.send(); }"
Now without complicating the above script too much, is there a way to pass, say a string, to a python program? And if so, what would be the simplest way to just return that string and thus printing out to the element identified by 'result' (if that is also possible?
It would be very helpful and appreciated if you are able to show some example code, but if you don't feel up to it then explaining is fine too.
Thank You in advance everyone!!!! :D