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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$(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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
  Write json data to csv Olive 6 1,446 Oct-22-2024, 06:59 AM
Last Post: Olive
  encrypt data in json file help jacksfrustration 1 2,384 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Read nested data from JSON - Getting an error marlonbown 5 2,756 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Reading Data from JSON tpolim008 2 2,620 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Convert nested sample json api data into csv in python shantanu97 3 5,632 May-21-2022, 01:30 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 3,393 May-09-2022, 02:49 AM
Last Post: snippsat
  json api data parsing elvis 0 1,399 Apr-21-2022, 11:59 PM
Last Post: elvis
  Capture json data JohnnyCoffee 0 1,815 Nov-18-2021, 03:19 PM
Last Post: JohnnyCoffee
  Serializing Python data Correctly (JSON) JgKSuperstar 4 3,253 Nov-04-2021, 07:31 PM
Last Post: JgKSuperstar
  How to save json data in a dataframe shantanu97 1 2,900 Apr-15-2021, 02:44 PM
Last Post: klllmmm

Forum Jump:

User Panel Messages

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