title: C# WebService send standard post request body, respond with JSON
body: <p>I'm having difficulty making a dynamic AJAX form submition method for .NET WebServices.</p>
  
  <p>The idea is to send a request that is dynamically built from all the inputs in a form. Then let the server respond with JSON.</p>
  
  <p>This is called when the form is submitted, it fills an array with the indexes as the input field name and the value as the value:</p>
  
  <pre><code>var params = [];
  
  for( var i in inputs )
  {
      if( inputs[i].type == 'text' || inputs[i].type == 'password' )
      {
          params[inputs[i].name] = inputs[i].value;
      }
  }
  </code></pre>
  
  <p>When the AJAX request is sent I run a loop to produce the request body:</p>
  
  <pre><code>var l = 0;
  for( var i in parameters )
  {
      this.parameters += ( l &gt; 0 ? '&amp;' : '') + i + '=' + parameters[i];
      l++;
  }
  </code></pre>
  
  <p>which gives a result like this:</p>
  
  <pre><code>foo=bar&amp;lol=haha
  </code></pre>
  
  <p>The problem is that script servicse only accepts JSON as the request body because of the decorator:</p>
  
  <pre><code>[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  </code></pre>
  
  <p>As I want it to return a JSON string rather than XML.</p>
  
  <p>Is there a simple solution?</p>