title: Implementing Ajax in php MVC
body: <p>Im want to implement Ajax in php mvc project, i want to add a user into the database using ajax.
  i tried to follow a youtube tutorial but couldn't insert the data, here is my index.html page:</p>
  
  <pre><code>  &lt;!DOCTYPE html&gt;
     &lt;html lang="en"&gt;
      &lt;head&gt;
       &lt;!-- Required meta tags --&gt;
       &lt;meta charset="utf-8"&gt;
       &lt;meta name="viewport" content="width=device-width, initial-scale=1,shrink-to-fit=no"&gt;
  
      &lt;!-- Bootstrap CSS --&gt;
      &lt;link rel="stylesheet" href="views/css/bootstrap.min.css" &gt;
    &lt;/head&gt;
    &lt;body&gt;
     &lt;div class="container"&gt;
      &lt;form&gt;
        &lt;div class="form-group"&gt;
         &lt;label for="name"&gt;Name:&lt;/label&gt;
         &lt;input type="text" class="form-control" id="name" placeholder="Enter Name"&gt;
        &lt;/div&gt;
        &lt;div class="form-group"&gt;
          &lt;label for="email"&gt;Email:&lt;/label&gt;
          &lt;input type="email" class="form-control" id="email" placeholder="Enter Email"&gt;
         &lt;/div&gt;
         &lt;button type="submit" onclick="saveData()"&gt;Add&lt;/button&gt;
        &lt;/form&gt;
       &lt;/div&gt;
  
       &lt;!-- jQuery first, then Tether, then Bootstrap JS. --&gt;
      &lt;script src="views/js/jquery.js"&gt;&lt;/script&gt;
      &lt;script src="views/js/bootstrap.min.js" &gt;&lt;/script&gt;
      &lt;script&gt;
       function saveData(){
        var name=$('#name').val();
        var email=$('#email').val();
        $.ajax({
         type: "POST",
         url: "?controller=pages&amp;action=add",
         data: "name="+name+"&amp;email"+email,
         success:function(msg){
         alert('Success,ajotuer fil base');
       }
      });
      }
    &lt;/script&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>and here is my controller funciton :</p>
  
  <pre><code>public function add(){
    if (isset($_POST['name']) || isset($_POST['email'])){
      echo 'error couldnt retreive inputs';
    }
    else {
      $name = $_POST['name'];
      $email = $_POST['email'];
      User::save($name,$email);
    }
  }
  </code></pre>
  
  <p>the user.php file </p>
  
  <pre><code>public static  function save($name,$email){
    $db = Db::getInstance();
    $req = $db-&gt;prepare("INSERT into user(id,name,email) VALUES ('',?,?)");
    $req-&gt;bindParam(1,$name);
    $req-&gt;bindParam(2,$email);
    $req-&gt;execute();
  }
  </code></pre>
  
  <p>UPDATE 1:Added full index.html file</p>