title: Passing string to JavaScript function from the server side
body: <p>I'm trying to pass a string parameter to a javascript function from the server side which will be posted to an AJAX method. The html is dynamically generated at the server side and I'm calling the javascript function using onclick property. The problem is that it works for a numeric value but I get an internal server error when I pass in a string value.</p>
  
  <p>here's my server side code:</p>
  
  <pre><code>str.Append("&lt;span class=\"button-accept\"&gt;&lt;a class=\"btn btn-primary btn-sm\" onclick=\"Request('"+from.ToString()+"')\" href=\"#\"&gt;&lt;i class=\"fa fa-check\"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;");
  </code></pre>
  
  <p>Here's my javascript method:</p>
  
  <pre><code>function Request(param) {
          $.ajax({
              type: "POST",
              url: '&lt;%= ResolveUrl("~/myaccount/notifications/Default.aspx/Accept") %&gt;',
              data: "{'param' : "+param+"}",
              contentType: "application/json",
              success: function (msg) {
                  msg = msg.hasOwnProperty("d") ? msg.d : msg;
                  alert(msg);
              }
          });
      }
      function OnSuccess(response) {
          alert(response.d);
      }
  </code></pre>
  
  <p>and here's the method that will be called by AJAX:</p>
  
  <pre><code>        [WebMethod]
      public static string Accept(string param)
      {
          return param;
      }
  </code></pre>
  
  <p>What's the right way to do this?</p>