How to set "Content-Type" for webix.DataCollection on Save


const url = "api/data.json"; new webix.DataCollection({ url: url, save: url }); //like this webix.ajax().headers({ "Content-Type": "application/json" }).post(url, JSON.stringify(data));
Tagged:

Comments

  • edited March 14

    Hello,

    Please try the save function:

    new webix.DataCollection({
      url: url,
      save: function(id, operation, update){
         return webix.ajax().headers({
           "Content-Type": "application/json"
         }).post(url, JSON.stringify(update));
      }
    });
    

    where

    • id is record id;
    • operation is "insert", "update" or "delete"
    • update is record data

    Also, you can use a json proxy that will automatically send data as JSON by RESTful requests (POST, PUT or DELETE based on operation type):

    new webix.DataCollection({
      url: url,
      save: "json->"+url
    });
    
  • that great solution thank you. @Helga

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion