You did not cancel the default submit action of the form so the page refreshes.
function submit(e) {
e.preventDefault();
$.ajax({
url: 'index.php',
type: POST,
data: $('form.ajax').serialize(),
success: function(response) {
alert(response);
}
});
}
//needs to be called on document ready
$('form.ajax').on("submit", submit);
If you insist on doing it the way you have it coded.
Add return false;
at the function and onclick="return submit()"