php - Ajax does not send data -
good morning everyone,
i kind of newbie concerning ajax. have php script works. know php needs evolve pdos problem. want implement ajax avoid reloading , because want learn it.
php script:
<?php session_start(); require "connect.php"; $firstname = $_post['regfirstname']; $lastname = $_post['reglastname']; $companyname = $_post['regcompanyname']; $email = $_post['regemail']; $password = $_post['regpassword']; $confirmpwd = $_post['regconfirmpwd']; $add = mysqli_query($con,"insert user (firstname, lastname, companyname, email, password) values ('$firstname' , '$lastname', '$companyname', '$email', '$password') ") or die("can't insert! "); mail($email, "your registration has been successful, please note registration details\n\n id: $email\n\n password: $password\n\n" ); $success = "successful! <a href='../login.php'> click here </a> log in."; echo($success);
and below ajax script:
$(document).ready(function(){ $("#regform").submit(registration); function registration(){ var regdata = $("#regform").serialize(); $.ajax({ url: "regscript.php", type: "post", data: regdata, success: function(){ console.log("ok"); }, error: function(){ console.log("regdata"); } }); });
and form:
<form id="regform" name="regform"> <div> <input type="text" id="regfirstname" name="regfirstname"> </div> <div> <input type="text" id="reglastname" name="reglastname"> </div> <div> <input type="text" id="regcompanyname" name="regcompanyname"> </div> <div> <input type="email" id="regemail" name="regemail"> </div> <div> <input type="password" id="regpassword" name="regpassword"> </div> <div> <input type="password" id="regconfirmpwd" name="regconfirmpwd"> </div> <br> <div id="errorwindowregister"> </div> <br> <button type="reset" name="reset" id="rstregister" href="#">reset</button> <button type="submit" name="submit" id="regbutton">register</button> </form>
i don't know how retrieve data ajax php. jquery code seems work data not sent php.
how retrieve data ajax , send php?
regards, e
you forgot add semicolon in script. anyway don't stop event when sending form. think have problem.
$(document).ready(function(){ $("#regform").submit(registration); function registration(){ var regdata = $("#regform").serializearray(); $.ajax({ //... })//; semi-colon missing here }) // edit: , here ')' ? });
add console output if have errors, please.
edit
if ajax request problem, following should solve problem. can't see modification made. i'm sur @ 99% sample helpful.
$(document).ready(function(){ $("#regform").submit( function(e) { e.preventdefault(); // avoid page reload var regdata = $("#regform").serialize(); $.ajax({ url: "regscript.php", type: "post", data: regdata, datatype: "html", // want retrieve html (i guess it's default it's better explicit) success: function(myreturnedhtml){ console.log(myreturnedhtml); // put result want } //... }); }); });
Comments
Post a Comment