php - duplicate page content after ajax to the same page -


i have simple registration formulae , want want firstly send ajax , without refreshing page control if insert correct data , redirect other page. problem after send through ajax same page working content of page being duplicate, can see twice...

here ajax

function registruj () {     var name = $('#meno').val();     var priez = $('#priezvisko').val();     var log  = $('#login').val();     var mail  = $('#mail').val();     var cislotel  = $('#cislo').val();     var heslo = $('#heslo').val();     var heslo1 = $('#heslo1').val();      $.post( "", {             'meno': name,             'priezvisko': priez,             'login':log,             'mail':mail,             'cislo':cislotel,             'heslo':heslo,             'heslo1':heslo1,          }, function (data) {             $('#result').html(data);          }       );      $('#nove').load(document.url + ' #nove');  } 

and php file

<?php  session_start(); if(isset($_post["meno"]) ) {     echo "kokot";     echo $_post['meno'];     require "pripojenie.php";     $meno = $_post["meno"];     $priezvisko = $_post["priezvisko"];     $login = $_post["login"];     $heslo = $_post["heslo"];     $hesloznovu = $_post["heslo1"];     if(isset($_post["pohlavie"]))         $pohlavie = $_post["pohlavie"];     $mail = $_post['mail'];     $cislo = $_post['cislo'];     //$id = $_session['id'];    } ?>  <!doctype html> <html> <head>     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta charset="utf-8" />     <title>blblblbl</title>     <link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.4.css" media="screen" />     <script src="jquery-1.4.3.min.js"></script>     <script type="text/javascript" src="./fancybox/jquery.mousewheel-3.0.4.pack.js"></script>     <script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.4.pack.js"></script>     <script>$(function(){$('.img').fancybox();});</script>      <style type="text/css"> </style>      <script type="text/javascript" src="mojskript.js"></script>     <link rel="stylesheet" href="css/normalize.css">     <link rel="stylesheet" type="text/css" href="css/style1.css" /> </head> <body  class="registracia"> <div class="container">  <div id="nove">                   <form  >              <table >                 <tr><td><label for="napdis">vyplňte nasledujúci formulár:</label></td></tr>                 <tr><td><input type="radio" name="pohlavie" value="zena" id="zena" >Žena</td></tr>                 <br>                 <tr><td><input type="radio" name="pohlavie" value="muz" id="muz">muž</td></tr>                 <br>                 <tr><td><label for="meno">meno :</label></td><td><input type = "text" id="meno" name="meno"></td></tr><br>                 <tr><td><label for="priezvisko">priezvisko :</label></td><td><input type = "text" id="priezvisko" name="priezvisko"></td></tr><br>                 <tr><td><label for="login">login :</label></td>                     <td><input type = "text" id="login" name="login"></td></tr><br>                  <?php                 if(isset($heslo)) {                     if (($heslo != "" && $hesloznovu != "") && ($heslo == $hesloznovu)) {                          $heslook = 1;                     }                     else {                         echo '<tr><td><label for="heslo">heslo :</label><td><input type = "password" name="heslo"></td><td><label for="zleheslo">heslá sa nezhodujú</label></td></tr>';                         $pocet = 1;                     }                 }                  ?>                 <?php                  if(!isset($pocet)) {                      echo'<tr ><td ><label for="heslo" > heslo :</label ></td >                     <td ><input type = "password"  id="heslo" name = "heslo" ></td ></tr ><br >';                 }                 ?>                 <tr><td><label for="heslo2">heslo znovu :</label></td>                     <td><input type = "password"  id="heslo1" name="heslo1"></td></tr><br>                 <?php                 if(isset($mail)) {                     if (!stristr($mail, "@") or !stristr($mail, ".")) {                         echo '<tr><td><label for="email">e-mail :</label></td>                         <td><input type = "text"  name="email"></td><td><label for="zlymail">zlý formát emailu</label></td></rd></tr><br>';                     } else {                         $mailok = 1;                     }                 }                 else {                     echo '<tr><td><label for="email">e-mail :</label></td>             <td><input type = "text" id="mail" name="email"></td></tr><br>';                  }                  ?>                  <tr><td><label for="cislo">telefónne číslo :</label></td>                     <td><input type = "text" id="cislo" name="cislo"></td></tr><br>                 <tr><td><input type="button" value="zaregistrovať" onclick="registruj()" ></td></tr>             </table>         </form>          <?php         if(isset($mailok) && isset($heslook)) {             $length = 20;              $randomstring = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"), 0, $length);               $zasifrovane = crypt($heslo,$randomstring);             echo $zasifrovane;             mysql_query("insert uzivatelia (meno,priezvisko,login,heslo,mail,pohlavie,cislo) values ('$meno','$priezvisko','$login','$zasifrovane','$mail','$pohlavie','$cislo')");             header("location:index.php");         }         ?>      </div>          <div id="result"></div>     </div>     </body> 

how should ?

try use exit(); :

session_start(); if(isset($_post["meno"]) ) {     echo "kokot";     echo $_post['meno'];     require "pripojenie.php";     $meno = $_post["meno"];     $priezvisko = $_post["priezvisko"];     $login = $_post["login"];     $heslo = $_post["heslo"];     $hesloznovu = $_post["heslo1"];     if(isset($_post["pohlavie"]))         $pohlavie = $_post["pohlavie"];     $mail = $_post['mail'];     $cislo = $_post['cislo'];     //$id = $_session['id'];     exit(); } 

use exit(); or die(); when ajax processing done otherwise return page content.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -