title: Ajax in jQuery with ASP.NET - return string
body: <p>I'm trying to write a simple ajax call with jQuery in ASP.NET.</p>
  
  <p>Here is the Ajax call in JavaScript file:</p>
  
  <pre><code>$.ajax(
          {
              url: "AjaxCall.aspx/GetSquare",
              dataType: "text",
  
              success: function (data) {
                  alert(data);
              },
  
              error: function () { alert("Ajax Error"); }
          });
  </code></pre>
  
  <p>And here is the web method in .aspx file:</p>
  
  <pre><code>[WebMethod]
      public string GetSquare()
      {
          return "OK";
      }
  </code></pre>
  
  <p>And this is what I get in alert:</p>
  
  <pre><code>!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;   
  &lt;head&gt;&lt;title&gt;    
  &lt;/title&gt;&lt;/head&gt;    
  &lt;body&gt;    
      &lt;form method="post" action="GetSquare" id="form1"&gt;    
  &lt;div class="aspNetHidden"&gt;   
  &lt;input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZLfZC2ZpNR/9g+3q7Z3ARCxIRMMXrN2MoePSYHvaiYH3" /&gt; 
  &lt;/div&gt;
      &lt;div&gt;    
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Why returned value was whole html markup instead of "OK"?</p>