Following the example given here I am trying to setup a simple client/webserver to use javascript as client and python as server. However, I seem to do something wrong, as I do not get an output on the server side (and no error message in the javascript console).
The complete files are exampleClient.html
:
<html>
<body>
<script src="jquery.js"></script>
<script>
function toPython(usrdata){
$.ajax({
url: "localhost:8082",
type: "POST",
data: { information : "You have a very nice website, sir." , userdata : usrdata },
dataType: "json",
success: function(data) {
//s <!-- do something here -->
$('#somediv').html(data);
}});
}
$("#filter").click(toPython("something5"));
//$("#onclick").bind('click', toPython("something5"));
</script>
<input type="button" id="filter" name="filter" value="Filter" />
<p id="demo"></p>
</body>
</html>
and server.py
:
# Python and Gevent
from gevent.pywsgi import WSGIServer
from gevent import monkey
monkey.patch_all() # makes many blocking calls asynchronous
def application(environ, start_response):
if environ["REQUEST_METHOD"]!="POST": # your JS uses post, so if it isn't post, it isn't you
start_response("403 Forbidden", [("Content-Type", "text/html; charset=utf-8")])
return "403 Forbidden"
start_response("200 OK", [("Content-Type", "text/html; charset=utf-8")])
r = environ["wsgi.input"].read() # get the post data
print(r)
return r
address = "localhost", 8082
server = WSGIServer(address, application)
server.backlog = 256
server.serve_forever()
I would appreciate help to fix the problem, or if you have another working example of how to create such a client/server setup...
tag.
– Shreyash S Sarnayak Jul 23 '17 at 13:51