title: syntax of passing json object using Ajax
body: <p>Im trying to pass these json object to the code behind</p>
  
  <pre><code>var obj = {
          Name: '1',
          Starting: '3',
  
          Timeline: [
          {
              StartTime: '111',
              GoesFor: '111'
  
          }
          ,
          {
              StartTime: '112',
              GoesFor: '112'
  
          }
  
      ]
      };
  </code></pre>
  
  <p>of course the next step is to stringify the object</p>
  
  <pre><code>var data = JSON.stringify(obj);
  </code></pre>
  
  <p>after that I use a jquery ajax call to pass the value to code behind</p>
  
  <pre><code>$.ajax({
              url: 'default.aspx/test',
              type: 'POST',
              contentType: 'application/json',
              data: data,
              success: function(result) {
                  $('#result').html(result.d);
              }
          });
  </code></pre>
  
  <p>the point is im getting error form the jquery library</p>
  
  <pre><code>POST http://localhost:63050/default.aspx/test 500 (Internal Server Error)
  </code></pre>
  
  <p>the problem is solved when I remove the obj variable, and put it into the JSON.stringfy method, like this</p>
  
  <pre><code>var data = JSON.stringify({
              obj: {
                  Name: '1',
                  Starting: '3',
  
                  Timeline: [
                  {
                      StartTime: '111',
                      GoesFor: '111'
  
                  }
                  ,
                  {
                      StartTime: '112',
                      GoesFor: '112'
  
                  }
                  ]
              }
          });
  </code></pre>
  
  <p>Is there anyway to passing the entire object variable into the json.stringify function, instead of declare and initializing within the function?</p>
  
  <p>In case you guys wanted to know, my code behind looks something like this</p>
  
  <pre><code>public class MyModel
  {
      public string Name { get; set; }
      public string Starting { get; set; }
      public testing2[] Timeline { get; set; }
  }
  
  public class testing2
  {
      public string StartTime { get; set; }
      public string GoesFor { get; set; }
  }
  
  [WebMethod]
      public static string Test(MyModel obj)
      {
          return "Hello from test" + obj.Name + obj.Starting + obj.Timeline[0].StartTime + obj.Timeline[1].StartTime;
      }
  </code></pre>