Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
ajax post data from javascript to python

Im trying to send a dict from javascript code to a python script via ajax through post. Heres the js:

    function foo(){
      context = {
         'var1': val1,
         'var2': val2
       }
       $.ajax({
         url:'/pyfoo'
         type: 'POST'
         data: context,
         success: function(){
            ...
         }
       });

I need to pull var1 and var2 from context in python but it doesn't come through. Any help would be appreciated.

I've tried a few thing in python:

def pyfoo():                                                                 
  data = json.loads('context')  
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

From flask examples on their site :

def pyfoo() : 
    try:
        data = json.loads(request.data)
        print(data)
        return "Success" 200
    except ValueError:
        error('Unable to parse JSON data from request.')
        return "Error" 400
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!