title: post text on same page without refresh using FETCH and send the data to the database
body: <p>I'm a beginner in php / javascript, so please be indulgent with me ahah</p>
  <p>I want to be able to post text and show the the result on the same page without reload the page. I also need to send the data to the database (this part should be fine as I've done it few times in the past)</p>
  <p>My HTML</p>
  <pre class="lang-html prettyprint-override"><code>&lt;div class=&quot;container&quot;&gt;
    &lt;form method=&quot;POST&quot; action=&quot;&quot; class=&quot;d-flex flex-wrap justify-content-end&quot;&gt;
      &lt;input class=&quot;form-group add-tweet&quot; type=&quot;text&quot; placeholder=&quot;What's happening ?&quot;      id=&quot;postTweet&quot;&gt;
      &lt;input type=&quot;submit&quot; value=&quot;envoyer&quot; id=&quot;submitTweet&quot;&gt;
    &lt;/form&gt;
    &lt;div class=&quot;tweet-container&quot;&gt;
      &lt;p id=&quot;tweet-value&quot;&gt;I want to show my data here&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>document.getElementById(&quot;submitTweet&quot;).addEventListener(&quot;click&quot;, postTweet);
  function postTweet(e) {
    e.preventDefault();
    const inputTweet = document.getElementById(&quot;postTweet&quot;).value;
    const containerTweet = document.getElementById(&quot;tweet-value&quot;);
    //const tweet = (containerTweet.innerHTML = inputTweet);
  
    const myTweet = {
      body: inputTweet,
    };
  
    fetch(&quot;index.php?action=home&quot;, {
      method: &quot;POST&quot;,
      headers: {
        Accept: &quot;application/json&quot;,
      },
      body: JSON.stringify(myTweet),
    })
      .then((res) =&gt; res.json())
      .then((data) =&gt; {
        data = containerTweet.innerHTML = myTweet;
      })
      .catch((err) =&gt; {
        console.log(&quot;u&quot;);
      });
  }
  </code></pre>
  <p>My repository</p>
  <pre class="lang-php prettyprint-override"><code>  public function postTweet($id_user, $tweet)
    {
      $sql = &quot;INSERT INTO tweet (ID_user, text, date) VALUES (:ID_user, :tweet, NOW())&quot;; 
      $query = $this-&gt;connect()-&gt;prepare($sql);
      $query-&gt;execute([
        &quot;ID_user&quot; =&gt; $id_user,
        &quot;tweet&quot; =&gt; $tweet,
      ]);
    }
  }
  </code></pre>
  <p>Controller</p>
  <pre class="lang-php prettyprint-override"><code>$postTweet = $TweetRepository-&gt;postTweet($userId, &quot;this is a test&quot;);
  </code></pre>
  <p>my method is working fine and I can send the data to the database, but now I've just have no idea how can I make my js and php &quot;working&quot; together. I watched many tutorial on youtube but still can't make it works. Anyone can help me or give me some advices please ?</p>
  <p>thanks</p>