1

A simple call like this:

type = 'theType';
category = 'theCategory';
$('#mydiv').load(
  '${request.route_url('theUrl')}',
  {type:type, category:category}
);

results in a "No JSON object could be decoded" error when I try to access the request.json_body object. Looking at the request, I can see that it is a POST, X-Requested-With: XMLHttpRequest, and that the body is type=theType&category=theCategory, which certainly isn't JSON.

What am I doing wrong?

I'm using Pyramid 1.3, Mako 0.72, jQuery 1.7.2

tshepang
  • 12,111
  • 21
  • 91
  • 136
Hollister
  • 3,758
  • 2
  • 20
  • 22

1 Answers1

1

jQuery.load() does not send JSON. In pyramid, simply access the form variables like you would with a normal POST request:

request.params['type']

etc.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Yes, that does explain it. I find it counterintuitive since $.ajax does send JSON data (if you `JSON.stringify` it). Too bad there's no option to tell jQuery how to encode the data. Thanks. – Hollister Sep 10 '12 at 17:33