Search code examples
kendo-uidatasourcecrudiceniumeverlive

Kendo DataSource reads my remote database but won't save things to it


It can Read the remote database, it can Create new items locally, but they don't actually save to the remote database. This is what adds a new item:

function addNewItem(){
  dataSource.add({id:"0", petName:"Dusty", petSpecies:"Dog", petGender:"M"});
  dataSource.sync();
}
$('#addPet').bind('click', addNewItem);

This ajax POST call in that function instead of the dataSource stuff adds to my database perfectly:

var object = { id:"0", petName:"Dusty", petSpecies:"Dog", petGender:"M" };
$.ajax({
  type: "POST",
  url: 'website/petData',
  headers: { "Authorization" : "Bearer ${AccessToken}" },
  contentType: "application/json",
  data: JSON.stringify(object)
}) 

Here is my datasource code. What do I need to change? I've tried doing sooooo many different things but no luck yet.

var dataSource = new kendo.data.DataSource({
  type: "everlive",   
  transport: {
    typeName: 'petData',
    read: {
      url: "website/petData",
      dataType: "jsonp"
    },
    create: {
      url: 'website/petData',
      dataType: "jsonp"
    }
  },
  group: "petSpecies",
  schema: {
    model: {
      id: "id",
      fields: {
        id: { type: "number"},
        petName: { type: "text" },
        petSpecies: { type: "text" },
        petGender: { type: "text" }
      }
    }
  }
});

Solution

  • So thanks to giltnerj0 and Brett's comments, I was able to google the right words, and discovered that all I needed to do was change create's dataType:jsonp to json. I'm getting some POST errors now, but it's POSTing finally and saving things to my database.

    create: {
      url: 'website/petData',
      dataType: "json"
    }