title: Basic Ajax with jQuery - Execute PHP File
body: <p>For some reason I can't get this to work. All I want to do is that when a button is clicked, (via ajax) a php file is executed. Aka, if I weren't using ajax, we'd be looking at:</p>
  
  <pre><code>&lt;a href="file.php"&gt;dfgdfg&lt;/a&gt;
  </code></pre>
  
  <p>I want the file to be executed without leaving the page.</p>
  
  <p>This is what I've got atm:</p>
  
  <pre><code>$(".vote-up").live('click', function(e) {
  $.ajax("file.php", function(){
         alert("Executed file");
     });
  });
  </code></pre>
  
  <p>That doesn't seem to be working. I'm just really confused how the jQuery ajax function functions in general, without dealing with anything remotely complicated.</p>
  
  <p>Added question:</p>
  
  <pre><code>.ajax({
         url: 'includes/login-check-jquery.php',
         success: function (data) {
              if(data == 1){
                  alert("Logged in!!!");
              }else{
                  window.location = data;
              }
          error: function (xhr, status, error) {
          // executed if something went wrong during call
          if (xhr.status &gt; 0) alert('Error: ' + status); // status 0 - when load is interrupted
          }
      });
  });
  </code></pre>
  
  <p>In the above code, if the data returned equals "logged in" than a message box appears. Otherwise it'll redirect to the location (that is sent in data). For some reason this if statement isn't working, but the data is being returned as expected.</p>
  
  <p>My PHP code is:</p>
  
  <pre><code>&lt;?php  
  if (!$user-&gt;logged_in){
      echo "../login/index.php";
  }else{
      echo "1";
  }
  </code></pre>
  
  <p>?></p>
  
  <p>Any ideas?</p>