title: Sending form data as JSON - Browser changing Content-Type
body: <p>I'm trying to create an HTML page that can submit the form data to the server in the form of JSON. I consulted the answers to <a href="https://stackoverflow.com/questions/1255948/post-data-in-json-format-with-javascript">this question</a> and am using the following code to do this:</p>
  
  <pre><code>&lt;head&gt;
     &lt;title&gt;Test&lt;/title&gt;
     &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
     &lt;script type="text/javascript" src="http://www.json.org/json2.js"&gt;&lt;/script&gt;
     &lt;script type="text/javascript"&gt;
       $(function() {
         var frm = $(document.myform);
         var dat = JSON.stringify(frm.serializeArray());
  
         alert("I am about to POST this:\n\n" + dat);
  
         $.ajax({
            type: "POST",
            data: dat,
            success: function(){},
            dataType: "json",
            contentType : "application/json"
          });
       });
     &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body onload="javascript:document.myform.submit()"&gt;
  &lt;form action="http://www.foo.com/" method="post" name="myform"&gt;
      &lt;input name="firstName" value="harry" /&gt;
      &lt;input name="lastName" value="tester" /&gt;
      &lt;input name="toEmail" value="testtest@test.com" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>However, if I intercept the request using Burp proxy tool, I can see that for some reason, the Content-Type becomes <code>application/x-www-form-urlencoded</code> as soon as the request leaves the browser. Here's a screenshot of the request:</p>
  
  <p><img src="https://i.stack.imgur.com/Dbp5V.jpg" alt="enter image description here"></p>
  
  <p>I would like to know why is this happening with the request? Why is the browser changing the Content-Type in the request? Is there a better way to do this?</p>
  
  <p>PS: I've tried this without jQuery (using XHR as explained <a href="https://stackoverflow.com/a/13038218/1382832">here</a>).</p>