serializing and submitting a form with jQuery POST and php -
i'm trying send form's data using jquery. however, data not reach server. can please tell me i'm doing wrong?
// form <form id="contactform" name="contactform" method="post"> <input type="text" name="nume" size="40" placeholder="nume"> <input type="text" name="telefon" size="40" placeholder="telefon"> <input type="text" name="email" size="40" placeholder="email"> <textarea name="comentarii" cols="36" rows="5" placeholder="message"> </textarea> <input id="submitbtn" type="submit" name="submit" value="trimite"> </form> javascript:
javascript code in same page form: <script type="text/javascript"> $(document).ready(function(e) { $("#contactform").submit(function() { $.post("getcontact.php", $("#contactform").serialize()) //serialize looks name=textinnameinput&&telefon=textinphoneinput---etc .done(function(data) { if (data.trim().length >0) { $("#sent").text("error"); } else { $("#sent").text("success"); } }); return false; }) }); </script> and server-side:
/getcontact.php $nume=$_request["nume"]; // $nume contains no data. tried $_post $email=$_request["email"]; $telefon=$_request["telefon"]; $comentarii=$_request["comentarii"]; can please tell me doing wrong?
edit: checked var_dump($_post) , returned empty array.
the weird thing same code tested on local machine works fine. if upload files on hosting space stops working.
tried doing old-fashioned form without using jquery , data correct.
i don't see how server configuration problem. ideas?
thank you!
you can use function
var datastring = $("#contactform").serialize(); $.ajax({ type: "post", url: "your url.php", data: datastring, datatype: "json", success: function(data) { //var obj = jquery.parsejson(data); if datatype not specified json uncomment // ever want server response }, error: function() { alert('error handing here'); } }); return type json
edit: use event.preventdefault prevent browser getting submitted in such scenarios.
Comments
Post a Comment