title: how to pass string parameter to webmethod in a web service from JQuery
body: <p>Here is my webmethod in a web service (local to the sample project) .asmx</p>
  
  <pre><code>[WebMethod]
      public List&lt;test1&gt; GetLstB(string s)
      {
          test1 t;
          List&lt;test1&gt; lstB = new List&lt;test1&gt;();
          t = new test1()
          {
              itm1 = "aaa" + s,
              itm2 = "bbb" + s
          };
          lstB.Add(t);
  
          t = new test1()
          {
              itm1 = "ccc" + s,
              itm2 = "ddd" + s
          };
          lstB.Add(t);
  
  
          return lstB;
      }
  
  public class test1
  {
      public string itm1 { get; set; }
      public string itm2 { get; set; }
  }
  </code></pre>
  
  <p>and here is the JQuery that calls this webmethod</p>
  
  <pre><code>$(function () {
      $("[id*=Button4").click(function () {
          var x = 'xyz';
          $.ajax({
              type: "POST",
              url: "ServiceCS.asmx/GetLstB",
              data: "{'" + x + "'}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",            
              success: function (result) {
                  for (var i in result.d) {
                      alert(result.d[i].itm1 + "--" + result.d[i].itm2);
                  }
              },
  
              error: function (r) {
                  alert(r.responseText);
                  console.log("AJAX error in request: " + JSON.stringify(r, null, 2));
              },
              failure: function (r) {
                  alert(r.responseText);
              }
          });
          return false;
      });
  });
  </code></pre>
  
  <p>I ran this JQuery function without passing a parameter (var x = 'xyz';)  and the webmethod returned the object list which I iterated through in JQuery without any problems.  But then I decided to try passing a parameter to the webmethod (also tried "xyz") and now I get this error -- how do I pass the parameter var x = "xyz"; to the webmethod correctly?</p>
  
  <p>"Message\":\"Invalid object passed in, \u0027:\u0027 or \u0027}\u0027 expected. (7): {\u0027xyz\u0027}\",\"StackTrace\":\"   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\r\n   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n   at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n   at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodDat</p>