I use jQuery to store the values of my javascript objects. I need to return the id of the inserted object from the database. I know how to do this if the Save function is inside a javascript object (see code below). But how can I set an identifier variable if the save function is not in the javascript object?
AT:
Person = function() {
var self = this;
self.ID;
self.Name;
self.SurName;
self.Save = function() {
$.ajax({
type: "POST",
url: "Save",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Name: self.Name, SurnName: self.SurName }),
dataType: "json",
success: function (result) {
var ID = result.d.ID;
self.ID = ID;
}
});
};
}¨
So, how do I now implement a function (outside the Person! Class), for example:
SavePerson = function(p) {
$.ajax({
type: "POST",
url: "Save",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Name: p.Name, SurnName: p.SurName }),
dataType: "json",
success: function (result) {
var ID = result.d.ID;
p.ID = ID;
}
});
};
source
share