Created
October 29, 2013 14:18
-
-
Save tonijz/7215517 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<html> | |
<head> | |
</head> | |
<body> | |
<div class="container"> | |
<form method="post" action=""> | |
<div id="error-msg" style="display:none;">loading...</div> | |
<input type="text" name="something1"> | |
<input type="text" name="somethin2"> | |
<input type="text" name="somethin3"> | |
<input type="text" name="somethin4"> | |
<input type="submit" value="Submit"> | |
</form> | |
</div> | |
<script type="text/javascript"> | |
$(function() { | |
// listent to submit event for specific element | |
$('.container form').submit(function() { | |
// serialize form fields | |
var data = $(this).serialize(); | |
$.ajax({ | |
url: base_url + '/some/controller', | |
type: 'POST', | |
data: data, | |
success: function(response) { | |
// if there's no error hide the modal window | |
if(response == '') { | |
$('.modal').destroy(); // Can't remember right method to hide the modal | |
} | |
else { | |
$('#error-msg').html(response); | |
} | |
} | |
}); | |
// don't refresh the page | |
return false; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment