title: How to solve Invalid JSON Primitive error on Ajax?
body: <p>I am trying to perform ajax using webmethod on Asp.net,</p>
  <p>And I am using <strong>JQuery-3.1.1</strong></p>
  <p>I want to pass the value to server and get back the value. I don't know what I did wrong.</p>
  <p><strong>Asp.net Code</strong></p>
  <pre><code>&lt;div class=&quot;row&quot;&gt;
     &lt;asp:Button ID=&quot;btnSave&quot; runat=&quot;server&quot; CssClass=&quot;btn btn-info&quot;  Text=&quot;save&quot; /&gt;
  &lt;/div&gt;
  </code></pre>
  <p><strong>Jquery Code</strong></p>
  <pre><code>$(document).ready(function () {
      $('#btnSave').click(function () {
          var name= 'xxx';
  
          $.ajax({
              type: &quot;POST&quot;,
              url: &quot;AjaxWebMethod.aspx/getFileExistOrNot&quot;,
              data: '{fileName:'+name+'}',
              contentType: &quot;application/json; charset=utf-8&quot;,
              dataType: &quot;json&quot;,
              success: OnSuccess,
              failure: function (response) {
                  alert(&quot;failed =&quot;+response.d);
              },
              error: function (response) {
                  alert(&quot;error =&quot;+response.d);  //This alert is executing
              }
          });
  
          function OnSuccess(response) {
              alert(&quot;Result =&quot;+response.d.mydata);
          }
          return false;
      });
  });
  </code></pre>
  <p><strong>C# code</strong></p>
  <pre><code>public partial class AjaxWebMethod : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
  
      [WebMethod]
      public static string getFileExistOrNot(string fileName)
      {
          string mydata=&quot;ajaxworking&quot;;
          return mydata;
      }
  }
  </code></pre>
  <blockquote>
  <p>I don't know really where I did my mistake</p>
  </blockquote>
  <p><strong>Error message on console</strong></p>
  <blockquote>
  <p>{Message: &quot;Invalid JSON primitive: xxx.&quot;,…}</p>
  <p>ExceptionType:&quot;System.ArgumentException&quot;</p>
  <p>Message:&quot;Invalid JSON primitive: xxx.&quot;</p>
  </blockquote>
  <p>Can you give the solution with proper reason. that will good for me to understand more, thanks</p>