I was able to hook ajax with django, but I’m running into the following problem.
In my ajax function, I have this:
function submitForm() {
var contactForm = $(this);
if ( !$('#senderName').val() || !$('#senderEmail').val() || !$('#message').val() ) {
$('#incompleteMessage').fadeIn().delay(messageDelay).fadeOut();
contactForm.fadeOut().delay(messageDelay).fadeIn();
} else {
$('#sendingMessage').fadeIn();
contactForm.fadeOut();
$.ajax( {
url: contactForm.attr( 'action' ) + "?ajax=true",
type: contactForm.attr( 'method' ),
data: contactForm.serialize(),
success: submitFinished
} );
}
return false;
}
And the view now looks like this:
def postMessageForm(request):
if request.POST:
print "POST"
if request.GET:
print "GET"
How do I tell the view to send the success variable back so the code continues?
In php, it would be something like this:
….
if ( isset($_GET[“ajax”]) ) {
echo $success ? “success” : “error”;
Thanks in advance
hmmm is it
But u can check whether request is ajax by using
request.is_ajax()