I have a dictionary in Javascript which I am passing to a function in Django. But when I try to access the data in POST it says that the key message is not found when the key clearly exists. Ive been scratching my head over this one. Im new to Javascript and Jquery so im sure I made a simple mistake.
Heres the code:
function share(id) {
var message = $('textarea#message').val();
var postData = { message: message, id: id };
$.post( "/{{ username }}/post/", postData, function ( json ) {
$('#posts').load(' #posts', function(){$(this).children().unwrap()})
} );
}
The exact error:
MultiValueDictKeyError at /Mohammed/post/ “Key ‘message’ not found in ” Request Method: POST
UPDATE
So I have narrowed down the issue and its that var message is not getting a value. The html which I am trying to grab the value from is as follows:
<textarea class="input-xlarge inputConvo" value = "" name="message" id="textarea" rows="2" style="width:98%; min-width:98%; max-width:98%;" placeholder="Share something with <user>."></textarea>
Thanks for the help
Aha! You are not getting at the element correctly. Try this:
The
#syntax means get the element with theidof textarea. Not the name. You can change theidto message and use$('#message').val();