Created
May 19, 2010 20:53
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% block scripts %} | |
<script type="text/javascript" charset="utf-8"> | |
$(function(){ | |
$('#submit').click(function(){ | |
var username = $("input#id_username").val(); | |
var password = $("input#id_password").val(); | |
$form = $('#login_form'); | |
$form.find('.errorlist').remove(); | |
errordata = '<ul class="errorlist"><li>There was a server error processing your login. Please try again.</li></ul>' | |
$.ajax({ | |
type: "POST", | |
url: "{% url ajax_login %}", | |
data: { | |
'username': username, | |
'password': password, | |
}, | |
success: function(data, textStatus, XMLHttpRequest){ | |
console.log(data) | |
if (data.valid == false) { | |
errors = '<ul class="errorlist">'; | |
$.each(data.errors, function(key, val) { | |
if (key.indexOf('__all__') >= 0) { | |
$.each(data.errors, function(key, val) { | |
errors += '<li>' + val + '</li>' | |
}); | |
} else { | |
errors += '<li><strong>' + key + ': </strong>' + val + '</li>' | |
} | |
}); | |
errors += '</ul>'; | |
$form.prepend(errors); | |
} else { | |
window.location.href = '{{ settings.LOGIN_REDIRECT_URL }}'; | |
} | |
}, | |
error: function(XMLHttpRequest, textStatus, errorThrown){ | |
$(errordata).insertAfter('#dropdown h2'); | |
} | |
}); | |
return false; | |
}); | |
}); | |
</script> | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment