Solved

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

Posted on 2014-04-14
3
836 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 51

Expert Comment

by:Julian Hansen
Comment Utility
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
Comment Utility
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
Comment Utility
Simple error, found the problem.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now