ziedinjsh Posted October 25, 2012 Report Share Posted October 25, 2012 (edited) Sveiki. Lieta tāda, ka nospiežu pogu reģistrēties man vnk pārlādējas lapa un neparāda erroru vai success msg. Lapai nemaz nevajag pārlādēteies :? html: <div id="error" style="display:none;">error</div> <div id="success" style="display:none;">success</div> <form method="post" id="register"> <p>Pseidonīms</p> <input type="text" name="username" class="input" /> <p>Dzimums</p> <select name="genere" class="select"> <option value="m">Vīrietis</option> <option value="f">Sieviete</option> </select> <p>Epsts</p> <input type="text" name="email" class="input" /> <p>Parole</p> <input type="password" name="password" class="input" /> <p><input type="submit" name="reg" value="Reģistrēties" class="button" /></p> </form> jQuery: jQuery(document).ready(function(){ jQuery('#register').submit(function(event) { event.preventDefault(); dataString = jQuery("#register").serialize(); jQuery.ajax({ type: "post", url: "process/register.php", dataType:"json", success: function (response) { if(response.status === "success") { jQuery('#success').html(response); } else if(response.status === "error") { jQuery('#error').html(response); } } }); return false; }); }); un php: <?php include("dbase.php"); $username = mysql_real_escape_string($_POST['username']); $genere = mysql_real_escape_string($_POST['genere']); $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $password2 = md5($password); $date = date('d.m.Y'); $check = mysql_query("select * from users where email='$email'") or die(mysql_error()); $result = mysql_num_rows($check); if(empty($username) || empty($email) || empty($password)){ echo json_encode(array('status' => 'error', 'message' => 'Kāds no lauciņiem ir palicis tukšs!' )); }elseif($result==1){ echo json_encode(array('status' => 'error', 'message' => 'Šāda epasta adresi ir jau reģistrēta.')); }elseif(!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email)){ echo json_encode(array('status' => 'error', 'message' => 'Epasts norādīts nepareizi.')); }else{ mysql_query("insert into users (username, genere, email, password, date) values ('$username', '$genere', '$email', '$password2', '$date')") or die(mysql_error()); echo json_encode(array('status' => 'success', 'message' => 'Reģistrācija veiksmīga')); } ?> Edited October 25, 2012 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
vostro Posted October 25, 2012 Report Share Posted October 25, 2012 Laikam tu nezinu, kas ir firebug console? Quote Link to comment Share on other sites More sharing options...
reiniger Posted October 25, 2012 Report Share Posted October 25, 2012 <p><input type="button" name="reg" value="Reģistrēties" class="button" /></p> vienkaršāk nomaini pogas tipu uz button un tad ar jquery click funkciju izpildi savas darbības. Quote Link to comment Share on other sites More sharing options...
vostro Posted October 26, 2012 Report Share Posted October 26, 2012 reiniger, a kas submit maina no button? $('#register').submit(function () { //Šeit dari ko gribi :) return false; }); Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 26, 2012 Author Report Share Posted October 26, 2012 tur jau tā lieta ka debug neko nerāda! Quote Link to comment Share on other sites More sharing options...
mad182 Posted October 26, 2012 Report Share Posted October 26, 2012 <p><input type="button" name="reg" value="Reģistrēties" class="button" /></p> vienkaršāk nomaini pogas tipu uz button un tad ar jquery click funkciju izpildi savas darbības. Pilnīgi un galīgi nepareizs piegājiens. Kas tādā gadījumā būs, ja lietotājam nebūs javascript atbalsta, vai arī viņš gluži vienkārši nospiedīs "enter"? Quote Link to comment Share on other sites More sharing options...
indoom Posted October 26, 2012 Report Share Posted October 26, 2012 Ja js neizpildas, tad visdrīzāk skripos ir kāds js errors, ko var redzēt js konsolē. Man jau arī patīk, kā ajax tiek postots bez nekādiem datiem. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted October 26, 2012 Report Share Posted October 26, 2012 Es izmantoju "button" noud. ``` <button>Click me!</button> ``` Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.