1

I have the following code, using Crockford's json2 to parse the object into json data.

using chrome dev tool the parsed string is "{"query":"asd"}".

However on the django server side, I keep getting an exception when I try to decode the post json data. Turns out the parsed json string became a key in the dictionary.

The query dict from the POST became this: {u'{"query":"asd"}': [u'']}, the json data became the key and the value became an empty string.

Is there a way to rectify this? so the result would be normal json data when the server receives it.

    // convert object to JSON data
    var jsonQuery = JSON.stringify(prod_query); 

    $.ajax({
        type: 'POST',
        url: '/company/product/item_search.json/',
        data: jsonQuery,
        success: //do stuff
                   }
        });
    }
});

python view

query = simplejson.loads(request.POST)

1 Answer 1

3

You want to pass request.raw_post_data to simplejson.loads.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.