Skip to content

Instantly share code, notes, and snippets.

@jbubriski
Created July 15, 2013 14:59
Show Gist options
  • Save jbubriski/6000657 to your computer and use it in GitHub Desktop.
Save jbubriski/6000657 to your computer and use it in GitHub Desktop.
Injecting AJAX result into a form before submitting. This is just a sample, it's not complete.
(function() {
$(function() {
var dataRequested = false;
var $form = $('#form');
$form.on('submit', function() {
if (!dataRequested) {
callMethodToGetAjaxData();
return false;
}
});
function callMethodToGetAjaxData() {
var $hiddenState = $('#state_textbox');
$.ajax({
url...
data...
success: function(data) {
dataRequested = true;
$hiddenState.val(data.d.state);
$('#form').submit();
}
});
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment