title: Reload a div on AJAX success
body: <p>I have a div which has PHP code (it prints data from a database). I made an AJAX function to send the data to the server without refreshing the page, here's the code:</p>
  
  <pre><code>var url = "loadsave.php";
  
     $('.create_save').submit(function(event) {
          if ($('.gss_new_save').val()==""){
              event.preventDefault();     
          } else {
              $.ajax({
                      type: "POST",
                      url: url,
                      data: $('form').serialize(),
                      success: function()
                      {
  
                      }
                  });
              event.preventDefault();
          }
      });
  </code></pre>
  
  <p>And this is the other part that prints the code. The problem is that it prints the code just when you refresh the page:</p>
  
  <pre><code>&lt;?php
              $connect = new PDO('mysql:host=localhost;dbname=game','root','');
              $cmd = $connect-&gt;query('SELECT * FROM saves');
              $result = $cmd -&gt; fetchAll(PDO::FETCH_ASSOC);
  
              foreach ($result as $res) {
                  ?&gt;
                  &lt;div class="gss_save cls"&gt;
                      &lt;span class="gss_save_text cls"&gt;&lt;?php echo $res['name'];?&gt;&lt;/span&gt;
                      &lt;span class="gss_level"&gt;lvl: &lt;?php echo $res['level'];?&gt;&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;?php
              }
          ?&gt;
  </code></pre>
  
  <p>EDIT: I add: the form:</p>
  
  <pre><code>&lt;form method="post" action="loadsave.php" class="create_save"&gt;
              &lt;input type="text" class="gss_new_save" name="name"&gt;
              &lt;input type="submit" style="display:none"&gt;
          &lt;/form&gt; 
  </code></pre>
  
  <p>and the content of loadsave.php:</p>
  
  <pre><code>&lt;?php
          if (isset($_POST['name'])) {
              $nombre = $_POST['name'];   
          }
  
          $connect = new PDO('mysql:host=localhost;dbname=game','root','');
  
          $stm = $connect-&gt;query("SELECT * FROM saves WHERE `name` ='$nombre'");
          $result = $stm-&gt;fetchAll(PDO::FETCH_ASSOC);
  
          if(count($result)==0){
              $cmd = $connect-&gt;prepare('INSERT INTO saves (name, level) VALUES (:nombre,"1")');
              $cmd -&gt; bindParam(":nombre",$nombre);
              $cmd -&gt; execute();
          }
      ?&gt;
  </code></pre>
  
  <p>It works like a charm but I want to refresh the div to print the content I just sent, how can I achieve this?</p>