Feb-22-2020, 09:26 PM
I have a file (runwsgi.py) that starts the server with the intention of getting a variable from a form using an ajax. The problem that prints the value none? See the wsgi code below, because I can't find an error:
Ajax section :
Wsgi section :
The output I get from the ws_search_field variable is: None
Note: Debugging in the chrome browser I see in the Form Data section it is possible to view the variable with the input value (ws_search_field: text)
Would there be an error to get the variable value in the code below?
Ajax section :
1 2 3 4 5 6 7 8 9 |
$( '.btn' ).text( 'search' ).click(function() { / / atribui valor a variavel var ws_search_field = $( '.ws-search-field' ).val(); / / set method ajax: $.ajax({ type : 'POST' , url : 'runwsgi.py' , data : { ws_search_field : ws_search_field }, dataType : 'json' , |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import cgi def apps(environ, ws_output): ws_mtd = environ[ 'REQUEST_METHOD' ] ws_form = cgi.FieldStorage() ws_input = ws_form.getvalue( 'ws_search_field' ) if ws_mtd = = 'POST' : status = '200 OK' headers = [( 'Content-type' , 'text/html; charset=utf-8' )] ws_output(status, headers) return [ str (ws_input).encode( 'utf-8' )] |
Note: Debugging in the chrome browser I see in the Form Data section it is possible to view the variable with the input value (ws_search_field: text)
Would there be an error to get the variable value in the code below?
1 2 |
ws_form = cgi.FieldStorage() ws_input = ws_form.getvalue( 'ws_search_field' ) |