Skip to content

Instantly share code, notes, and snippets.

@tonijz
Created October 29, 2013 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonijz/7215517 to your computer and use it in GitHub Desktop.
Save tonijz/7215517 to your computer and use it in GitHub Desktop.
<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