Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get json data
#1
I have a working jquery file that sends data in json format to a wsgi file as follows:

$(document).ready(function() {

    $('.btn').text('search').click(function() {
        // atribui valor a variavel
        var wsi_search = $('.ws_search').val();
        // set method ajax:
        $.ajax({
            type: 'POST',
            url: '/kosmos',
            data: { wsi_search: wsi_search },
            dataType: 'json',
            // function shoot efect:
            beforeSend : function() {
            },
            // end callback:
            complete : function() {
            },
            // shoot event moment feedback server:
            success : function() {
                alert('ok')
            },
            // monstra erro na requisição
            error : function() {
            },
        });
    });
});
How do I get the json data?
Below is the wsgi code:

from wsgiref.simple_server import make_server
from wsgiref.util import request_uri

def apps(environ, ws_output):

    ws_mtd = environ['REQUEST_METHOD']
    ws_url = request_uri(environ, include_query=True)

    if ws_mtd == 'POST':
        
        # Tratar o method post :
        status = '200 OK'
        headers = [('Content-type', 'text/html; charset=utf-8')]
        ws_output(status, headers)
        return [str('Dados Json').encode()]

with make_server('', 8000, apps) as httpd:
    print('Running wsgi\nBrowser access - http://127.0.0.1:8000\nCrl+c for exit command or Crl+z for stop')
    httpd.serve_forever()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 208 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Read nested data from JSON - Getting an error marlonbown 5 1,367 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Reading Data from JSON tpolim008 2 1,080 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Convert nested sample json api data into csv in python shantanu97 3 2,815 May-21-2022, 01:30 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 1,887 May-09-2022, 02:49 AM
Last Post: snippsat
  json api data parsing elvis 0 929 Apr-21-2022, 11:59 PM
Last Post: elvis
  Capture json data JohnnyCoffee 0 1,198 Nov-18-2021, 03:19 PM
Last Post: JohnnyCoffee
  Serializing Python data Correctly (JSON) JgKSuperstar 4 2,104 Nov-04-2021, 07:31 PM
Last Post: JgKSuperstar
  How to save json data in a dataframe shantanu97 1 2,158 Apr-15-2021, 02:44 PM
Last Post: klllmmm
  Sort data from JSON file Dummy_in_programming 2 2,443 Jan-04-2021, 06:17 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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