title: Jquery ajax() function won't load PHP script
body: <p>I'm trying to create a simple login with PHP and MySQL and I'm using the AJAX() jquery function to load the PHP script.
  All that I want to do is to load a new web page (for example java2s.com) when the script finds the user in my database.
  Problem is that the script won't work at all.
  This is the HTML with the Jquery:</p>
  
  <p>EDIT: This is the fixed code thanks to all those who commented, which sadly still doesn't work.</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt; Login &lt;/title&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script language="JavaScript"&gt;
  function change()
  {
  document.location.href="http://www.java2s.com";
  }
  
  $(document).ready(
  $("#loginForm").click(function() {
  var jsonlogin=new Object();
  jsonlogin.username=$('#username').val();
  jsonlogin.password=$('#password').val();
  var sendstr = JSON.stringify(jsonlogin);
  $.ajax({
          type: 'POST',
          url: 'login.php',
          async: false,
          contentType: 'application/json; charset=utf-8',
          dataType: 'json',
          data: sendstr,
          success:function(response){
          if (response['result']=="login successful")
              {
              change();
              }
          }
      });
  
      })
    )
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt; INSERT USERNAME AND PASSWORD&lt;/h1&gt;
  &lt;input type="text" id="username" name="username"&gt; USERNAME &lt;br&gt;
  &lt;input type="password" id="password" name="password"&gt; PASSWORD &lt;br&gt;
  &lt;input type="submit" id="loginForm" class="button positive"&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The PHP script is very simple:</p>
  
  <pre><code>&lt;?php
  $data = file_get_contents('php://input');
  $result = json_decode($data);
  $con=mysqli_connect("localhost","****","*****","*******");
  $str="SELECT ID FROM users WHERE username='".$result-&gt;username."' AND password='".$result-&gt;password."';";
  $exists = mysqli_query($con,$str);
  if (mysqli_num_rows($exists) ==1)
  {
      $arr = array('result'=&gt;"login successful");
      $ris=json_encode($arr);
      echo $ris;
  }
  else
  {
      $arr= array('result'=&gt;"login error");
      $ris=json_encode($arr);
      echo $ris;
  }
  mysqli_close($con)
  ?&gt;
  </code></pre>
  
  <p>When I load the page and press the submit button nothing will happen.
  Anyone can help?
  Thank you very much in advance</p>