1

I'm using XAMPP and mod_wsgi to execute my python scripts. So far I'm able to execute my python code by clicking on a button I've created. I'm trying to send data to a python script from a html page, do some stuff, and send back an alert on the page.

Below is my HTML code which just has a button and I'm trying to send the value 84 to my python script and send it back. Right now I just get a popup that says "None" so I'm pretty sure the problem is in the python script and how it receives the data.

Any help would be greatly appreciated!

    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
                    <title>Conveyor</title>
                    </head>

    <body>
    <script>
    getTxt = function (){

      $.ajax({
        data: {param1:'84.0'},
        url:'test.py',
        type: "post",
        success: function (response) {
            alert(response);
        }
      });
    }
    </script>
    </head><body>
      <button type="button" id="btnGetTxt" onclick="getTxt()">Send Number</button>
    </body></html>                                                          
    </body>                             
    </body>
    </html>

python script.

    import sys
    import cgi

    def application(environ, start_response):
        form = cgi.FieldStorage()
        status = '200 OK'
        name = form.getvalue('param1')

        output = str(name)
        response_headers = [('Content-type', 'text/plain'),('Content-Length', str(len(output)))]
        start_response(status, response_headers)

        return [output] 
saibot
  • 11
  • 4

0 Answers0