Sunday 15 March 2015

jquery - ajax() loses form data on submission -



jquery - ajax() loses form data on submission -

i have contact uses jquery ajax() submit form data. works on xampp on server, form info supposed sent php file becomes blank. nil @ sent external file

$(document).ready(function(){ $("input#regbut").click(function(){ var edin = $("input[name^='name']").val(); var mailer = $("input[name^='email']").val(); var dept = $("input:radio[name^='direct']:checked").val(); var hint = $("input[name^='subject']").val(); var bodied = $("textarea[name^='message']").val(); var seri = "name=" + edin + "&email=" + mailer + "&direct=" + dept + "&subject=" + hint + "&message=" + bodied; $("span#war").fadein(function(){ $("span#war").css("display", "block"); }); $("#warn").html(''); if(edin ==''){ $("#warn").html('you did not tell name'); }else if(mailer == ''){ $("#warn").html('your email required'); }else if(hint == ''){ $("#warn").html('subject required'); }else if(bodied == ''){ $("#warn").html('you did not tell problem is'); }else{ $.ajax({ type: "get", url: "contactpro.php", data: seri, error: function(){ $("#warn").html("sorry! error occurred"); }, success: function(repo){ $("#warn").html(repo); alert(repo); } }); } homecoming false; }); }); <form method="post" id="cotact"> <table width="80%" border="0" cellspacing="3" cellpadding="1"> <tr> <td></td> <td id="warn" style="color:#ff0000;"><h3 style="color:#0099ff;"><span id="war" style="display:none;">sending...</span></h3></td> </tr> <tr> <td>name</td> <td><label> <input name="name" type="text" class="input" id="sign_up" /> </label></td> </tr> <tr> <td>email </td> <td><label> <input name="email" type="text" class="input" id="sign_up" /> </label></td> </tr> <tr> <td>direct to</td> <td><p> <label> <input name="direct" type="radio" id="direct_0" value="1" checked="checked" /> general</label> / enquiry<br /> <label> <input type="radio" name="direct" value="2" id="direct_1" /> advertising</label> <br /> <label> <input type="radio" name="direct" value="3" id="direct_2" /> reports</label> <br /> <label> <input type="radio" name="direct" value="4" id="direct_3" /> suggestions</label> <br /> </p></td> </tr> <tr> <td>subject</td> <td><label> <input name="subject" type="text" class="input" id="sign_up" /> </label></td> </tr> <tr> <td>message</td> <td><label> <textarea name="message" cols="45" rows="5" class="input" id="sign_up" style="height:100px;"></textarea> </label></td> </tr> <tr> <td>&nbsp;</td> <td><label> <input type="submit" name="submit" id="regbut" value="submit" /> </label></td> </tr> </table> </form></td> </tr> <tr> <td colspan="2" align="center"></td> </tr> </table>

it's hard tell what's going on, seek passing object data in $.ajax phone call instead of query string have, example:

... $.ajax({ type: "get", url: "contactpro.php", data: { name: edin, email: mailer, ... }, error: function(){ $("#warn").html("sorry! error occurred"); }, success: function(repo){ $("#warn").html(repo); alert(repo); } }); ...

also, verify you're checking $_get since ajax request specifies request method (i notice form method post) you're not checking $_post? if want ajax request send via post, alter type "post"

jquery forms

No comments:

Post a Comment