please give me an example of back end remote using saveChanges from list box
back end in asp.net
waiting
document.getElementById('load').addEventListener("click", function () {
$.ajax({
async: false,
url: 'https://localhost:44303/api/values',
type: 'GET',
dataType: 'json',
success: function (data) {
listObj.dataSource = data.Value;
listObj.dataBind();
}
});
});
document.getElementById('add').addEventListener("click", function () {
listObj.addItems({ Id: 'game10', Name: 'Volley Ball' })
var postData = JSON.stringify({ Id: 'game10', Name: 'Volley Ball' });
$.ajax({
async: false,
url: 'https://localhost:44303/api/values',
type: 'POST',
dataType: 'json',
data: { jsonData: postData },
success: function (data) {
return data;
}
});
});
|
public static List<game> Games = new List<game> {
new game { Id = "game0", Name = "Badminton" },
new game { Id = "game1", Name = "Cricket" },
new game { Id = "game2", Name = "Football" },
new game { Id = "game3", Name = "Golf" },
new game { Id = "game4", Name = "Tennis" },
new game { Id = "game5", Name = "Basket Ball" },
new game { Id = "game6", Name = "Base Ball" },
new game { Id = "game7", Name = "Hockey" }
};
public JsonResult Get()
{
return new JsonResult(Games);
}
public void Post()
{
string jsonData = HttpContext.Current.Request.Params["jsonData"];
game game1 = new JavaScriptSerializer().Deserialize<game>(jsonData);
Games.Add(game1);
}
|