javascript - Undefined Variable When sending via Ajax -


i have form passes forn field values ajx script passes values php , they sent email address.

the problem have values not showing , instead word undefined.

here ajax code.

$(document).ready(function(){ $('form.save').submit(function () { var name = $(this).find('.name').attr('value'); var email = $(this).find('.email').attr('value'); var telephone = $(this).find('.telephone').attr('value'); // ...     $.ajax({         type: "post",         url: "application.php",         data: "name="+ name +"& email="+ email +"& telephone="+ telephone,         success: function(){             $('form.save').hide(function(){$('div.success')});         }     }); return false; }); }); 

here form

  <form action="" method="post" class="save">                                <input type="text" name="name"  id="name" clsss="name" value="" placeholder="name"/>                                <input  type="text" name="email"  class="email" value="" placeholder="email"/>                                 <input  type="text" name="telephone"  class="telephone" value=""placeholder="telephone"/>                              <input name="certified" type="checkbox" value="" checked>i certified sophisticated investor                             <input type="hidden" name="type" value="certified sophisticated investor">                             <input type="submit" name="submit" class="button" value="submit"/>                             </div>                       </form> 

and php (there no sanitation on php code trying value , use better php code)

 $name = $_post['name'];  $email = $_post['email'];  $telephone = $_post['telephone'];    // mail  $msg = "$name $email $telephone";  $msg = wordwrap($msg,70);  mail("*************","application",$msg); 

there few things wrong in code,

  • see statement here,

    <input type="text" name="name"  id="name" clsss="name" value="" placeholder="name"/>                                             ^ should class 
  • you're getting input field values in wrong way. should this:

    var name = $(this).find('.name').val(); var email = $(this).find('.email').val(); var telephone = $(this).find('.telephone').val(); 

so ajax request should this:

$(document).ready(function(){     $('form.save').submit(function () {     var name = $(this).find('.name').val();     var email = $(this).find('.email').val();     var telephone = $(this).find('.telephone').val();         $.ajax({             type: "post",             url: "application.php",             data: {name:name, email:email, telephone:telephone},             success: function(){                 $('form.save').hide(function(){$('div.success')});             }         });     return false;     }); }); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -