title: MediaWiki API: Edit section without destroying heading
body: <p>I'm trying to edit a section on a page on Wikipedia, but when I do so the whole section gets replaced by whatever text I send through the URL, even the heading, so it stops being a section. Is there any way to edit a section without deleting the heading?</p>
  
  <p>So far, the function I'm using (having admittedly stolen it from a documentation page) is as follows:</p>
  
  <pre><code>function editSection(section, summary, content, editToken) {
      $.ajax({
          url: mw.util.wikiScript('api'),
          data: {
              format: 'json',
              action: 'edit',
              title: mw.config.get('wgPageName'),
              section: section,
              summary: summary,
              text: content,
              token: editToken
          },
          dataType: 'json',
          type: 'POST',
          success: function(data) {
              if (data &amp;&amp; data.edit &amp;&amp; data.edit.result == 'Success') {
          window.location.reload();
              } else if (data &amp;&amp; data.error) {
                  alert('Error: API returned error code "' + data.error.code + '": ' + data.error.info);
              } else {
                  alert('Error: Unknown result from API.');
              }
          },
          error: function(xhr) {
              alert('Error: Request failed.');
          }
      });
  }
  </code></pre>
  
  <p>to get my edit token, I use</p>
  
  <pre><code>function getEditToken() {
      $.getJSON(
          'http://en.wikipedia.org/w/api.php?', {
              action: 'tokens',
              type: 'edit',
              format: 'json'
          },
          function(data) {
              if (data.tokens) {
                  wgEditToken = data.tokens.edittoken;
              }
          }
      )
  }
  </code></pre>
  
  <p>help please!</p>