title: ASP.NET 500 Internal Server Error while calling webmethod from javascript
body: <p>I'm trying to call the <code>webmethod</code> fucntionality using AJAX but unable to get the appropriate results. I have googled my problem and found many solution but those didn't worked for me. Please guide me what I'm doing wrong. Help will be appreciated.</p>
  
  <p>Cheers</p>
  
  <p><strong>Code Snippet</strong></p>
  
  <pre><code> function checkUserNameExists() {
  
  //initialization
  var pagePath = window.location.pathname + "/getUsername";
  var value = document.getElementById('control_userName').value;
  var dataString = "{ 'value':'" + value + "' }";
  $.ajax({
      type: "GET",
      url: pagePath,
      data: dataString,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      error:
              function (XMLHttpRequest, textStatus, errorThrown) {
  
              },
      success:
              function (result) {
                  var flag = true;
                  if (result != null) {
                      flag = result.d;
                      if (flag == "True") {
                          alert('okay fine you are good');
                      }
                      else {
                          alert('try again');
                      }
                  }
              }
  });
   }
  </code></pre>
  
  <p><strong>Method in Behind Code file</strong></p>
  
  <pre><code>    [WebMethod]
      [ScriptMethod(UseHttpGet = true)]
      public string getUsername(string value)
      {
          return "True";
      }
  </code></pre>
  
  <p><strong>EXCEPTION</strong></p>
  
  <pre><code> ExceptionType: "System.InvalidOperationException"
    Message: "An attempt was made to call the method 'getUsername' using a        POST request, which is not allowed."
  </code></pre>