0

I have a very basic email submission form in my ASP.NET MVC 3 app. I'm trying to integrate the jQuery form plug-in with it.

<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.form.js")"></script> 

<script type="text/javascript">
// prepare the form when the DOM is ready 
$(document).ready(function () {
    var options = {
        beforeSubmit:  showRequest,
        success: showResponse
    };

    // bind form using 'ajaxForm' 
    $('#mailform').ajaxForm(options);
});
function showRequest(formData, jqForm, options) {
    alert('request');
}
// post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
    alert('response');
}
</script> 
...
<form action="@Url.Action("SubmitEmail")" class="mail-form" id="mailform" method="post">
    <fieldset>
        <span class="txt">
            <input type="text" name="email" id="email" value="Enter Your Email Address" />
        </span>
        <input class="button" id="submitemail" type="submit" />
    </fieldset>
</form>

I've tested my non-AJAX version and it works just fine. When I try to use the jQuery plug-in, however, the showRequest function gets called, but the showResponse function doesn't-- and it doesn't seem like the method is ever called on the server either.

1 Answer 1

1

A couple things to check - you have a script tag for jQuery form but I don't see one for jQuery itself (you'd want to have jQuery listed before the plugin).

Also - install Fiddler or Firebug and make sure that requests are being sent out. And just to throw this out there, for a call this simple the form plugin is overkill. $.post would work just fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Andy. I went ahead and just used the $.post approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.