title: how to return a string instead of a full page with $.post()
body: <p>Well guys, with the following code:</p>
  
  <pre><code>$(document).ready(function() {
      $(".list-book-description").css("display", "none");
      $("#user-panel-login").css("display", "none");
      $('#login-form').submit(function(e) {
          e.preventDefault();
          var formUsername=$("#login-form #username").val();
          var formPassword=$("#login-form #password").val();
          if((formUsername.length&lt;6))
          {
          $("#ajax-output").html("&lt;div class='error'&gt;Attenzione username troppo breve!&lt;/div&gt;");
          }
          else if((formPassword.length&lt;6))
          {
              $("#ajax-output").html("&lt;div class='error'&gt;Attenzione password troppo breve!&lt;/div&gt;");
           }
      else
      {
          $.post(
              'index.php?module=login',
              {
                  "username": formUsername,
                  "password": formPassword,
              },
              function(data){
                  $("#ajax-output").html(data);
              }
          );
      }
  });
  });
  </code></pre>
  
  <p>i tried to pass to <code>?index.php&amp;module=login&amp;function=1</code> username and password got by <code>#login-form</code> fields <code>#username</code> &amp; <code>#password</code> to <code>login()</code> php function that uses <code>setLogin();</code> function if data is into database to set a login session.</p>
  
  <pre><code>function Login()
   {
   if(!checkLogin())
      {
      $function=@stringEscape($_GET['function']);
  
      if($function==1)
      {
          $username=stringEscape($_POST['username']);
          $password=sha1(stringCrypt($_POST['password'], 'sha1').stringCrypt(DB_CRYPT, 'sha1'));
          if(setLogin($username, $password))
          {
              echo "&lt;div class='ok'&gt;Login effettuato con successo, tra pochi secondi verrai riportato alla homepage!&lt;/div&gt;";
          }   
      }
  }
  else notfound();
  }
  
  function setLogin($username, $password, $time="")
  {
  if(!checkLogin())
  {
      if((isset($username)) &amp;&amp; (isset($password)))
      {
          $query=mysql_query("SELECT * FROM ".DB_PREF."users WHERE user_username='".$username."' AND user_password='".$password."'");
          if(mysql_num_rows($query))
          {
              $fetch=mysql_fetch_assoc($query);
              $_SESSION['logged_user_id']=$fetch['user_id'];
              $_SESSION['logged_user_username']=$fetch['user_username'];
              return true;
          }
          else
          {
              echo "&lt;div class='error'&gt;Dati non validi, ripeti la procedura di login o &lt;a href='?index.php&amp;module=registration'&gt;registrati&lt;/a&gt;!&lt;/div&gt;";
          }
      }
  }
  else notfound();
  }
  </code></pre>
  
  <p>Now i've a problem when i get the result of <code>$.post()</code> in my <code>#ajax-input</code> div submitting the login form, it doesn't return just the result of login function, but the index page+login function result.</p>
  
  <p>If i try to set "json" parameter into <code>$.post</code> function and <code>echo json_encode()</code> in php function it doesn't work at all. So, what could be the problem?</p>