title: Return a value from a WebMethod based on conditions provided in the WebMethod
body: <p>I have a jQuery Ajax WebMethod call as shown below:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          $("#btnsubmit").click(function () {
  
              var arr = new Array();
              arr.push($("#control1").val()); arr.push($("#control2").val()); arr.push($("#control13 option:selected").val()); arr.push($("#control4 option:selected").val()); arr.push($("#control15 option:selected").val());
  
              var requestedData = JSON.stringify(arr);
              requestedData = "{'details':'" + requestedData + "'}";
  
              $.ajax({
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  url: "EmployeeDemotion.aspx/Save",
                  data: requestedData,
                  dataType: "json",
                  success: function (result) {
                    //check the value returned from the WebMethod and provide alerts accordingly
  
                  },
  
                  error: function (result) {
                      alert("Error");
                  }
  
              });
          });
  
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>and, the WebMethod is as below:</p>
  
  <pre><code> [WebMethod(EnableSession = true)]
       public static InsertDetails[] Save(string details)
          {
  
              DataTable dt = new DataTable(); DataTable dts = new DataTable();
  
              List&lt;InsertDetails&gt; data = new List&lt;InsertDetails&gt;();
              JavaScriptSerializer js = new JavaScriptSerializer();
              string[] Tags = js.Deserialize&lt;string[]&gt;(details);
              object[] obj = new object[8];
              obj[0] = Tags[0].ToString(); obj[1] = Tags[1].ToString(); obj[2] = Tags[2].ToString(); obj[3] = Tags[3].ToString();
              obj[4] = Tags[4].ToString(); 
  
  
              int a = //say condition 1
              int b = //say condition 2
              if (a&lt; b)
              {
  
               //insert into database and set a value which says the insertion has succeeded
  
              }
              else
              {
                  //alert that data cannot be inserted
              }
  
              return data.ToArray();
          }
  </code></pre>
  
  <p>Now I require a value of any possible type (boolean,array,string,integer or other) to be returned to the ajax method so that the success function in the ajax method alerts the status of insertion (as commented in te snippet) i.e; a value should be returned along with the last statement "return data.ToArray();" to the ajax method.
  I do not require the  element 'data' to be returned, the value which validates the insertion should be returned either along with 'data' or in any other form.</p>