title: HTML5 Ajax JQuery PHP MySQL Insert
body: <p>Can anyone tell me, why I am still redirected to insertInput.php after pushing the submit button. I tried several things, but it didn't work, like changing the type from "submit" to "button" and so on.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Barocker's Song Voting&lt;/title&gt;
          &lt;link href="vote.css" type="text/css" rel="stylesheet"&gt;
          &lt;script src="jquery-1.11.0.min.js" type="text/javascript"&gt;&lt;/script&gt;
           &lt;script type="text/javascript"&gt;
              $(document).ready(function(){
                  $("#insert").click(function(){
                      var url = "insertInput.php";
                      var data = $("#form :input").serializeArray();
                      alert("Button clicked");
                      $.post(
                          url,
                          data,
                          function(info){
                              $("#result").html(info);
                          }
                      );
                      clearInput();
                  });
                  function clearInput(){
                      $("#form :input").each(function(){
                          $(this).val("");
                      });
                  }
              });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="insertBanner"&gt;
              &lt;form id="form" action="javascript:void(0);" method="post"&gt;
                  &lt;input type="text" id="title" name="title" style="width: 300px;" placeholder="Titel" autofocus required&gt;
                  &lt;input type="url" id="url" name="url" style="width: 300px;" placeholder="Link (Youtube, etc.)"&gt;
                  &lt;button id="insert"&gt;Hinzufügen&lt;/button&gt;
              &lt;/form&gt;
              &lt;span id="result"&gt;&lt;/span&gt;
          &lt;/div&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP:
      
  
  <pre><code>    /*
       * Connect to MySQL
       */
  
      $con = mysqli_connect("localhost", "@", "", "test");
  
      /*
       * Check Connection
       */
  
      if (mysqli_connect_errno()){
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
  
      $title = $_POST['title'];
      $url = $_POST['url'];
      $sql = "INSERT INTO barocker (title, url) VALUES ('" . $title . "', '" . $url . "')";
  
      if (!mysqli_query($con,$sql)){
          echo "Error";
      } else {
          echo "Success";
      }
  
      /*
       *  Close Connection
       */
  
      mysqli_close($con);
  
  ?&gt;
  </code></pre>
  
  <p>Thank you guys. Any help as always very appreciated.</p>