Kung Fu Ninja
Kung Fu Ninja

Reputation: 3752

jquery ajaxSubmit question

I am having a little bit of a trouble with the following:

<script>
$(document).ready(function() {
$('#sform').validate({
rules: { firstName: {required:true},
         lastName:  {required:true},
         emailAddress:  {required:true, email:true}
},
messages: { firstName: '<br/><span style="color:red;">Please enter your first name!</span>',
            lastName : '<br/><span style="color:red;">Please enter your last name!</span>',
            emailAddress: '<br/><span style="color:red;">Please enter a valid email address!</span>'
},
   submitHandler: function(form){
   var options = { 
                beforeSubmit:  showRequest,
                success: showResponse,
                type: 'post',
                url:'sendSurvey.cfm'
                };
    $(this).ajaxSubmit(options);
    return false;   
   }
 });
function showRequest(formData, jqForm, options) { 
 $('#formSub').html('We really appreciate your feedback!');
var queryString = $.param(formData); 
 alert('About to submit: \n\n' + queryString); 
  return true; 
 }
function showResponse(responseText, statusText) {
  alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
       '\n\nThe output div should have already been updated with the responseText.'); 
 }
 });
 </script>

The problem is that there is no form data being posted.$.param(formData) is null. what to do? thanks

Upvotes: 0

Views: 1096

Answers (1)

Nick Craver
Nick Craver

Reputation: 630469

You need to submit the <form>, so your content is a bit off, instead of this:

$(this).ajaxSubmit(options);

You need this:

$(form).ajaxSubmit(options);

Where you're calling this in the submitHandler, this refers to the validation object itself, not the <form>, so just use the form DOM element reference that gets passed in.

Upvotes: 1

Related Questions