title: How can I use json response from php in jquery?
body: <p>I'm trying to do a website. I need to get all the reviews in the database. My initial guess was to use php like this:</p>
  <pre><code>function get_all_reviews(){
      $db = dbConnection();
      $db -&gt; setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $query = &quot;SELECT Nome, Title, reviews.Review, users.Email FROM `users` JOIN `reviews` WHERE users.Email = reviews.Email; &quot;;
      $statement = $db -&gt; prepare($query);
      $statement-&gt;execute();
      $result = $statement-&gt;fetchAll(); 
      foreach ($result as $row) {
          $name = $row[&quot;Nome&quot;];
          $title = $row[&quot;Title&quot;];
          $review = $row[&quot;Review&quot;];
          $email = $row[&quot;Email&quot;];
          ?&gt;
      &lt;div class=&quot;box&quot; id=&quot;&lt;?= $email ?&gt;&quot;&gt;
      &lt;div class=&quot;nome&quot;&gt;&lt;?= $name ?&gt;  dice:&lt;/div&gt;
      &lt;div class=&quot;titolo&quot;&gt;&lt;?= $title ?&gt; &lt;/div&gt;
      &lt;div class=&quot;recensione&quot;&gt;&lt;?= $review ?&gt; &lt;/div&gt;
      &lt;button class=&quot;admin_bottom&quot;&gt;X&lt;/button&gt;
    &lt;/div&gt;
      &lt;?php    
  }
  </code></pre>
  <p>But since it's a project for the university, I need to not use it (it's mandatory). I need to send the request with jquery, then with php I should send the response with json, but I don't get how to recall the reviews and list them.
  I try with this with php:</p>
  <pre><code>function gett_all_reviews(){
          $db = dbConnection();
          $db -&gt; setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          $query = &quot;SELECT Nome, Title, reviews.Review, users.Email FROM `users` JOIN `reviews` WHERE users.Email = reviews.Email; &quot;;
          $statement = $db -&gt; prepare($query);
          $statement-&gt;execute();
          $result = $statement-&gt;fetchAll(); 
          $resultSet = '{ ';
          foreach ($result as $row) {
              $resultSet .= '{&quot;name&quot;: &quot;'.$row[&quot;Nome&quot;].'&quot;,';
              $resultSet .= '&quot;title&quot;: &quot;'.$row[&quot;Title&quot;].'&quot;,';
              $resultSet .= '&quot;review&quot;: &quot;'.$row[&quot;Review&quot;].'&quot;,';
              $resultSet .= '&quot;email&quot;: &quot;'.$row[&quot;Email&quot;].'&quot;},';
      
          }
          $resultSet .= '}';
          $db = null;
      
          
          return $resultSet;
      }
      $s = get_all_reviews();
      
      echo $s;
  </code></pre>
  <p>and with jquery:</p>
  <pre><code>$.getJSON( &quot;../php/get_reviews.php&quot;, function( json ) {
          
          for (let index = 0; index &lt; json.length; index++) {
              $(&quot;#conteiner_reviews&quot;).append(
                  &quot;&lt;div class=\&quot;box\&quot; id= \&quot;&quot;+ json[index].email+ &quot;\&quot;&gt;&quot;+
                      &quot;&lt;div class=\&quot;nome\&quot;&gt;&quot;+json[index].name +&quot; dice:&lt;/div&gt;&quot; +
                      &quot;&lt;div class=\&quot;titolo\&quot;&gt;&lt;&quot;+json[index].title+&quot;&lt;/div&gt;&quot;+
                      &quot;&lt;div class=\&quot;recensione\&quot;&gt;&quot;+json[index].review +&quot;&lt;/div&gt;&lt;/div&gt;&quot;);
          }
      });
  </code></pre>
  <p>But doesn't work.</p>