title: login form with ajax and javascript
body: <p>I tried to use ajax to show error message if username or password are incorrect, and to go to tabeeb.html or secc.php if they are correct. but instead of going to the correct page, the page is presented in the dialog, like this<a href="https://i.stack.imgur.com/IXDdz.jpg" rel="nofollow noreferrer">img</a>. what is the wrong? </p>
  
  <p>this is the form </p>
  
  <pre><code> &lt;form method="post"   class="bounceInDown animated"&gt;
   &lt;input type="text" name="u" id="u" placeholder="User Name" class="bbb"&gt;&lt;br&gt;
   &lt;input type="password" name="p" id="p" placeholder="Password" class="bbb"&gt;     
   &lt;input type="button" onClick="myFunction()"  name="loginbtn" class=" btn 
   btn-primary " value="Log in"&gt; 
   &lt;/form&gt;
  </code></pre>
  
  <p>this is myfunction() function</p>
  
  <pre><code>function myFunction(){
  
  var u = document.getElementById("u").value;
  var p = document.getElementById("p").value;
  var dataString = 'u1=' + u + '&amp;p1=' + p ;
  
   if (u == '' || p == '') {
  alert("Please Fill All Fieldsssssss");} 
  
  
  else {
  // AJAX code to submit form.
  $.ajax({
  type: "POST",
  url: "ajaxjss.php",
  data: dataString,
  cache: false,
  success: function(html) {
  
  alert(html);
  }
  });
  }
  return false;
  </code></pre>
  
  <p>and this is ajaxjss.php</p>
  
  <pre><code>&lt;?php
  // Fetching Values From URL
  $u2 = $_POST['u1'];
  $p2 = $_POST['p1'];
  
  $connection = mysql_connect("localhost", "root", "password"); 
  //   Establishing Connection with Server..
  $db = mysql_select_db("project", $connection); // Selecting Database
  
  if (isset($_POST['u1'])) {
  
  
  // من تحت هو التجربة
  $result = mysql_query("select * from test where student_name = '$u2' ") or 
   die("faild");
  
  $row = mysql_fetch_array($result);
  
  
  if($row['student_name'] == $u2 &amp;&amp; $row['student_password']==$p2)
  { $NoOFLetter = strlen($u2);
  
  $result = substr($u2, $NoOFLetter-3,  $NoOFLetter);
  if($result == "doc"){header('Location: tabeeb.html'); exit; }
  if($result == "sec"){header('Location: secc.php'); exit;}
  
   exit; }
  
  else{ 
  $error_message = "Error in username or password!";}
  
  // كل اللى فوق هو التجربة
  
  if(!$query){
  
  echo "error";
  
  }else{echo "Form Submitted succesfully";}}
  mysql_close($connection); // Connection Closed
  ?&gt;
  </code></pre>