I'm using ASP.NET MVC. So I have a form on my page:
<form id="MyForm" name="MyForm" method="post" action="http://www.mysite.com">
<input id="hdnType" name="hdnType" type="hidden" />
</form>
I'm using the jQuery submit action to do some validation before the form is posted. I also need to make an AJAX call to set "hdnType" based on other values from several dropdowns that I didn't include in this example:
$('#MyForm').submit(function()
{
if (!ValidForm())
return false;
$.ajax({
type: "POST",
url: '/Home/GetType',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response)
{
$('#hdnType').val(response);
}
});
return true;
}
Everything in the submit() function is supposed to run before the form posts. This was working correctly before I added that AJAX call, but now when the code reaches my AJAX call, the form posts before I can set "hdnType".
Is there a way around this?