Apart from what you have shared, the page only refreshes in case of when the result (of expression) is true. That is because you have not stopped the code from doing what it is intended to do, submit the form.
To overcome this, write this function to your code.
event.preventDefault()
would make sure that the page is not refreshed,
return false
in the other blocks does this for you and makes sure that the code doesn't propagate and form isn't submitted (indirectly page doesn't refresh).
$(function() {
$('.run').click(function(event) {
event.preventDefault();
var userid = document.getElementById('uid').value;
var password = document.getElementById('pass').value;
if(userid == 'heaven' && password == 'hell') {
alertify.success("Success");
return true;
}
else {
alertify.error("Failed");
return false;
}
});
});
Now when you will run the code, in both cases it won't submit the form.
I would still recommend that you remove those return statements. They are of no use as event handlers are not intended to return anything at all.