Created
July 15, 2013 14:59
-
-
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.
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
(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