1

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" }
      }
    }
  }
});
Timothy Walters
  • 16,866
  • 2
  • 41
  • 49
Shonna
  • 993
  • 2
  • 9
  • 12
  • Does the HTTP POST actually happen and return an error, or does it not even try to POST the new record ? If it does POST, what is the returned error, also, what does the object look like it tries to POST ? You could possibly try removing the id property from the object you add to the datasource and let the kendo datasource do that for you. I've had some issues with that in the past. – Robin Giltner Sep 06 '13 at 13:24
  • Do what @giltnerj0 is saying and look at your network tab in the browser's developer tools (F12) to see if the POST is even occurring. Also, you need to make sure that your controller action on the server **returns** the new object created by the POST. Kendo datasource needs this to update its internal list. – Brett Sep 06 '13 at 15:36
  • Ah, cool I didn't know you could see that stuff in the network tab. It's not doing a POST at all. It's doing GET instead. I tried removing the Id stuff as well, still no POST. – Shonna Sep 06 '13 at 16:29

1 Answers1

0

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"
}
Shonna
  • 993
  • 2
  • 9
  • 12