I have a simple form submission with ajax, but it keeps giving me an error. All the error says is error. No code, no description. No nothing, when I alert it when it fails.
Javascript with jQuery:
$(document).ready(function(){
$(.post-input).submit(function(){
var postcontent = $(.post-form).val();
if (postcontent == ){
return false;
}
$(.post-form).attr(disabled, disabled);
$.ajax({
url: '/post',
type: 'POST',
data: {post-form: postcontent},
dataType: json,
success: function(response, textStatus, jqXHR) {
alert(Yay!);
},
error: function(jqXHR, textStatus, errorThrown){
alert(textStatus, errorThrown);
}
});
});
});
HTML:
<form class=post-input action= method=post accept-charset=utf-8>
<textarea class=post-form name=post-form rows=1 cols=10 onFocus=this.value='';return false;>What are you thinking about...</textarea>
<p><input class=post-submit type=submit name = post.submitted value=Post></p>
</form>
and if there are no problems there, then the server-side (pyramid):
def post(request):
session = Session()
user = authenticated_userid(request)
postContent = request.POST['post-form']
if not postContent == '':
session.add(Activity(user.user_id, 0, postContent, None, None))
return {}
return HTTPNotFound()
UPDATE:
After some more debugging with firebug, I discovered that the post request body contains only post.submitted=Post, instead of the intended result of {post-form: postcontent}.