Last active
December 12, 2015 02:58
-
-
Save faceleg/4703441 to your computer and use it in GitHub Desktop.
Template for jQuery ajax handler that runs scripts contained in the returned data.
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
<form action="" method="post"> | |
<input type="text" name="name" /> | |
<button type="submit">Submit</button> | |
</form> | |
<div id="result"></div> | |
<script type="src/javascript"> | |
$.ajax({ | |
type: 'POST', | |
url: location.href, | |
data: $(this).serialize() | |
}).success(function(data) { | |
wrapper.animate({ opacity: 0 }, function() { | |
wrapper.html($.parseHTML(data)) | |
.animate({ opacity: 1 }); | |
// Run any scripts included in the returned HTML | |
$(data).filter('script').each(function() { | |
$.globalEval(this.text); | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment