Solved

My form validates but won't submit via ajax.. using jquery validate

Posted on 2014-04-14
3
841 Views
Last Modified: 2014-04-20
I open up the modal window with my form in it. Click 'Add' and the form validates fine but doesn't submit the url. Any idea what I'm missing?

<script type="text/javascript" charset="utf-8">	

$(function () {

$("#testdriveform").validate({

submitHandler: function (form) {
    $.ajax({
        type: "POST",
        url: "dplates/add/",
        data: $("#testdriveform").serialize()
    })
    .done(function (response) {
        if (response.success == 'success') {               
            alert('success');                       
        } else {
            alert('fail');
        }
    });
return false; 
},
        rules: {
            dPlate: {
                required: true,
                minlength: 6,
                maxlength: 6
            },
            rep_id: {
                required: true
            },
            firstName: {
                required: true
            },
            lastName: {
                required: true
            },
            phone: {
                required: true
            }
        }
    });

    $("#testdrive").dialog({
        autoOpen: false,
        width: 550,
        modal: true,
        buttons: {
            Add: function () {
                $("#testdriveform").submit();
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });

$( "#newdrive").live('click', function() {
$( "#testdrive" ).dialog( "open" );
id = $(this).data("id");
return false;
});
});
</script>

Open in new window

0
Comment
Question by:tjyoung
  • 2
3 Comments
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 40000962
Are you sure you are not getting in javascript errors?

Check your console for errors - if there is an error it will stop execution of the form which could be preventing the submit.

Do you have a test link we can look at?

Otherwise - can you post more of your code so we can test it.
0
 
LVL 1

Accepted Solution

by:
tjyoung earned 0 total points
ID: 40001222
HI,
After a nights sleep: problem was the rule for dPlate. something to do with minlength and maxlength. Removed, submitted perfectly.
Have to check the docs on it.
Thanks for taking the time.
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 40011193
Simple error, found the problem.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Performance for Office 365 6 48
jquery datatables, asp.net MVC 9 41
PHP AJAX JSON 2 61
How to deal with the query string 8 23
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question