Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem: Get variable
#1
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 :

    $('.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',
Wsgi section :

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')]
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?

ws_form = cgi.FieldStorage()
ws_input = ws_form.getvalue('ws_search_field')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  dynamic variable name declaration in OOP style project problem jacksfrustration 3 716 Oct-22-2023, 10:05 PM
Last Post: deanhystad
  Reset Variable problem IcodeUser8 3 2,312 Jul-20-2020, 12:20 PM
Last Post: IcodeUser8
  Variable from notepad problem samuelbachorik 2 2,259 Apr-10-2020, 09:04 AM
Last Post: samuelbachorik
  Problem defining a variable rix 6 3,135 Dec-17-2019, 11:34 AM
Last Post: rix
  Problem writing a variable value to Excel Chuck_Norwich 1 1,903 Jul-25-2019, 02:20 PM
Last Post: Chuck_Norwich
  Pass variable script return twice output problem Faruk 8 4,289 Dec-26-2018, 11:57 AM
Last Post: Faruk
  Problem with variable O_Pas_Sage 7 4,409 Aug-25-2018, 04:07 PM
Last Post: buran
  Trying to create a python exe for an addition problem with an odd variable Python_Newb 0 2,130 Nov-30-2017, 12:18 PM
Last Post: Python_Newb
  Problem With Scope Of A Variable Saif133 5 5,392 Jan-05-2017, 05:18 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020