title: How can I detect an error in AJAX?
body: <p>I have a jQuery function, which is using AJAX to send the necessary information to run the respective script properly:</p>
  
  <pre><code>$("#changeUseridForm").submit(function(){
      $.ajax({
          type: "GET",
          url: "API/root/users/changeUsername.php",
          data: {
          newUsername: ("#newUserid", this).val(),
          password: ("#retypePass", this).val(),
          xml: 1,
          },
          dataType: 'xml',
          success: function(xml){
              if($(xml).find("success").length &gt; 0){
                  alert("Username changed successfully!");
  
                  $("#changeUserid").hide();
                  $("#BackToMainMenu").hide();
                  $("#MainPage").show();
                  $("#AddLinkButton").show();
                  $("#ChangeUserOptions").show();
                  $("#ChangeUserDataButton").show();
                  $("#ShowPosts").show();
              }
              else if($(xml).find("error").length &gt; 0){
                  alert("You have to fill all the fields!");
              }
          }
      });
  
      return false;
  });
  </code></pre>
  
  <p>I have several functions like this one, running perfectly; this one isn't. I verified all my variables and scripts. They're spelled correctly. It doesn't reach to the script referenced. I think the AJAX code might have a problem, but I can't detect which error is. I tried to search it on my browser's web inspector, but I can't figure it out since the page is reloading for some reason that I don't know why. (Because this function doesn't have <code>window.location.reload()</code> in it anywhere.)</p>