title: jQuery Ajax using PHP function returns HTML code
body: <p>I'm using Joomla, and I intend to be checked in a database of Joomla user table is right there through a code in order to perform the registration.</p>
  
  <p>Well, 3 days ago I'm trying to use an ajax function that invokes a php function.
  What happens is that when I try to read the response from the server (php function) can only get HTML page. Not sure what is happening. I saw several articles and questions and still not know what's going on.</p>
  
  <p>What I'm doing is when the writing is detected in a given field, performs the function to check if the code exists in the database</p>
  
  <p>I am unsure if I am correctly access to my validatePartner.php</p>
  
  <p>Here is my script:
  </p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
  jQuery(document).ready(
      function($){
          $('#jform_username').bind('input', function() {
              alert("FINE");
  
              var data =" hello world";
              var data2=" hello all";
              $.ajax({
                  url: 'validatePartner.php',
                  data: {'q': data,'z':data2},
                  type: "POST",
                  success: function(data) {
                      alert("Here: " + data);
                  }
  
              });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is my validatePartner.php:
  </p>
  
  <pre><code>&lt;?php
   function myfunction() {
      $myvar = $_POST['q']." how are you?";
      $myvar2 = $_POST['z'];
      echo $myvar."\n".$myvar2;
  
   }
  
  myfunction();
  ?&gt;
  </code></pre>
  
  <p>I have this teo files in the same directory.</p>
  
  <p>Thanks for your help!</p>
  
  <p>SOLUTION:</p>
  
  <p>Using @jonasfh tips, I got what I need!
  I created a component with two files that he tells me and in ajax function I used:</p>
  
  <pre class="lang-js prettyprint-override"><code>&lt;script language="javascript" type="text/javascript"&gt;
  . . .
  $.ajax({
      url: '?option=com_validatepartner&amp;format=raw',
      . . .
  &lt;/script&gt;
  </code></pre>
  
  <p>Instead:</p>
  
  <pre class="lang-js prettyprint-override"><code>&lt;script language="javascript" type="text/javascript"&gt;
  . . .
  $.ajax({
      url: '?option=com_validatepartner&amp;tmpl=json',
      . . .
  &lt;/script&gt;
  </code></pre>
  
  <p>Thanks for the help!</p>