I have a simple presentation form with ajax, but it keeps giving me an error. All error indicates error. No code, no description. There is nothing when I warn about this, when he 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, then the server (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 additional debugging with firebug, I found that the message request body contains only post.submitted = Post, and not the intended result {"post-form": postcontent}.
source share