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')
json.loadsing the string you get in Python? How are you getting it?json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)jsonis essentially just a format for serializing a string-keyed hashmap as a string. Meaning you have to deserialize it when it gets where its going. It also seems that its not getting encoded by the client code, trydata: JSON.stringify(context),json.loads('context')? Why are you referencing the name of a client side variable in your server side code? What HTTP server are you using?