Submit form without page refresh (partially page refresh)
<p>Index.php in HTML head:</p>

<pre><code>&lt;head&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"&gt;&lt;/script&gt;
  &lt;script src="http://malsup.github.com/jquery.form.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    // wait for the DOM to be loaded
    $(document).ready(function() {
      // bind 'myForm' and provide a simple callback function
      $('#loginform').ajaxForm(function() {

        $.get("loginform.php", function(data) {
          $("#loginform1").html(data);
        });
      });
    });
  &lt;/script&gt;
&lt;/head&gt;
</code></pre>

<p>loginform.php:</p>

<pre><code>&lt;div id="loginform1"&gt;
&lt;?php if(!isset($_COOKIE['login']) &amp;&amp; $obj-&gt;checkCookie($database, $_COOKIE['login'])){ ?&gt;
&lt;form class="pure-form" id="loginform" method="POST" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
    &lt;fieldset&gt;
        &lt;legend style="width:500px;"&gt;Anmeldung&lt;/legend&gt;
        &lt;input type="text" name="username" placeholder="Benutzername"&gt;
        &lt;input type="password" name="password" placeholder="Passwort"&gt;
        &lt;button type="submit" name="submit" class="pure-button pure-button-primary"&gt;Login&lt;/button&gt;
    &lt;/fieldset&gt;
&lt;/form&gt;
&lt;?php } else { ?&gt;
  &lt;form class="pure-form" id="loginform" method="POST" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
      &lt;fieldset&gt;
          &lt;legend style="width:500px;"&gt;Anmeldung&lt;/legend&gt;
          &lt;button type="submit" name="logout" class="pure-button pure-button-primary"&gt;Logout&lt;/button&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;?php } ?&gt;
&lt;/div&gt;
</code></pre>

<p>The <strong>loginform.php</strong> is included in a file called <strong>header.inc</strong> which is included on <strong>index.php</strong>. </p>

<p>Right now the login works with ajax, the page doesn't refresh and it sets the cookies. But the login form doesn't refresh, so after logging in it doesn't display the logout button and the whole page doesn't display the content I want to display after logging in. After refreshing the page manually it displays the logout button and the content.</p>