Content API - POST - Documentation topics on: contentletapi,.

Content API - POST

Here is an example of a form that will perform a simple post and simple redirect upon posting the content.

<script type="text/javascript" >
     
    $(document).ready(function() {
     
    $("#webup").submit(function(e) {
    e.preventDefault();
   
      var dataObj= {
      'title': $('#title').val(),
      'body': $('#body').val(),
      'contentHost': 'demo.dotcms.com',
      'stName': 'webPageContent'
      };
     
      $.ajax({
          url: '/api/content/save/1',
          type: 'POST',
          cache: false,
          data: dataObj,
          beforeSend: function (request){
          // This sends the user who authenticates against the dotCMS server
          // In a real world example, you could use session based authentication
          request.setRequestHeader("DOTAUTH", window.btoa("admin@dotcms.com:admin"));
        },
   
        success: function(data,status,xhr) {
          window.location = "http://dotcms.com";
        },
        error: function(data,status,xhr) {
          alert("fail: " + data);
          console.log(data);
        },
          });
      });
    });
</script>
     
<form id="webup">
     
    <div class="form-group">
    <label for="title" class="required">Title</label>
    <input type="text" class="form-control" id="title" name="title" value="Here is a title">
    </div>
     
    <div class="form-group">
    <label for="body" class="required">Body</label>
    <textarea id="body" name="body" >Here is some texttest</textarea>
    </div>
     
    <br>&nbsp;<br>&nbsp;
    <div class="form-group">
      <input type="submit" value="Give 'er a go" />
    </div>
     
</form>