[Answer]-JQuery call not hitting server on $.post

1šŸ‘

Could be a couple things going on I think:

  1. Specify the content type in the jQuery call, make sure it says ā€˜appliciation/jsonā€™ (http://api.jquery.com/jQuery.ajax/) since youā€™re serializing assuming itā€™s JSON but it defaults to ā€˜application/x-www-form-urlencodedā€™.

  2. Your POST url expects a / at the end of its URL, and youā€™re posting to an endpoint without a /, which makes Django issue a redirect to the / URL. You can disable that by setting the APPEND_SLASH setting (https://docs.djangoproject.com/en/1.4/ref/settings/#append-slash), but really itā€™s best to always call all endpoints with ā€˜/ā€™ at the end, so Iā€™d say instead of posting with $.post(ā€œapicallā€, ā€¦), try $.post(ā€œapicall/ā€, ā€¦) and see if that helps.

Otherwise, can you post the error that you get when you do try? both from the Django console and the Javascript console in Chrome?

šŸ‘¤Teebes

0šŸ‘

Turns out it was wrapped in a form within the body of the HTML that I had not noticed. After removing the form wrapper it worked perfectly.

Leave a comment