Ho una semplice sottomissione di modulo con ajax, ma continua a darmi un errore. Tutto ciò che l'errore dice è "errore". Nessun codice, nessuna descrizione. No, quando lo avverto quando fallisce.Jquery ajax richiesta post non funzionante
JavaScript con 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>
e se non ci sono problemi lì, poi il lato server (piramide):
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: Dopo un po 'più di debug con firebug, ho scoperto che il corpo della richiesta post contiene solo post.submitted = Posta, invece del risultato previsto di {"post-form": postcontent}.
Si tratta di un errore di javascript (client), errore del server o errore python? – Hamish
@Hamish attraverso il mio debug, presumo che si tratti di un errore del client. – Wiz