title: jQuery .ajax post fails with large JSON object
body: <p>I am posting JSON data to an ASP.NET MVC2 server.  I am posting large JSON strings (which incorporate a base64-encoded file stream, read from the local file system).  The jQuery ajax call works fine up to file sizes of around 2.5Mb.  Once above this size the ajax call fails (never gets to the controller).  I can't detect exactly what the error is - it doesn not seem to populate the error variables.</p>
  
  <p>The ajax call is as follows:</p>
  
  <pre><code>$.ajax({
              type: "POST",
              dataType: 'json',
              timeout: 10000,
              url: "/Molecule/SaveMolecule",
              data: { jsonpost: postdata, moleculetype: _moleculeType, moleculefilestream: _moleculefilestream, changedproducts: stringifiedChangedProducts }, // NOTE the moleculeType being added here
              success: function (data) {
                  if (data.rc == "success") {
                      $.log('ServerSuccess:' + data.message);
  
                      molecule_updateLocalInstance();
  
                      _bMoleculeIsDirty = false;
                      if (bReturnToMoleculeList != null &amp;&amp; bReturnToMoleculeList == true) {
                          navigator_Go('/Molecule/Index/' + _moleculeType);
                      }
                      else {
                          _saveMoleculeButtonFader = setTimeout(function () {
  
                              $('#profilesave-container').delay(500).html('&lt;img src="/content/images/tick.png" width="32px" height="32px" /&gt;&lt;label&gt;' + _moleculeSingularTerm + ' was saved&lt;/label&gt;').fadeIn(500);
  
                              _saveMoleculeButtonFader = setTimeout(function () { $('#profilesave-container').fadeOut(1000); }, 2000);
  
                          }, 500);
                      }
  
                  } else {
                      $.log('ServerUnhappy:' + data.message);
                      RemoveMoleculeExitDialog();
                  }
              }
              , error: function (jqXHR, textStatus, errorThrown) {
                  alert('Save failed, check console for error message:' +textStatus+' '+ errorThrown);
                  MarkMoleculeAsDirty();
                  $.log('Molecule Save Error:' + helper_objectToString(textStatus+' '+errorThrown));
              }
          });
  </code></pre>
  
  <p>where _moleculefilestream is the large base64-encoded stream.</p>
  
  <p>My web.config includes the following:</p>
  
  <pre><code>&lt;system.web.extensions&gt;
      &lt;scripting&gt;
        &lt;webServices&gt;
          &lt;jsonSerialization maxJsonLength="50000000"&gt;
          &lt;/jsonSerialization&gt;
        &lt;/webServices&gt;
      &lt;/scripting&gt;
    &lt;/system.web.extensions&gt;
  </code></pre>
  
  <p>Anyone got any bright ideas?</p>