Skip to content

Instantly share code, notes, and snippets.

@roden0
Created May 22, 2013 11:09
Show Gist options
  • Save roden0/5626808 to your computer and use it in GitHub Desktop.
Save roden0/5626808 to your computer and use it in GitHub Desktop.
function RestServiceJs(newurl) {
this.myurl = newurl;
this.post = function(model, callback) {
$.ajax({
type: 'POST',
url: this.myurl,
data: JSON.stringify(model), // '{"name":"' + model.name + '"}',
dataType: 'text',
processData: false,
contentType: 'application/json',
success: callback,
error: function(req, status, ex) {},
timeout:60000
});
};
this.put= function(model, callback) {
$.ajax({
type: 'PUT',
url: this.myurl,
data: JSON.stringify(model), // '{"name":"' + model.name + '"}',
dataType: 'text',
processData: false,
contentType: 'application/json',
success: callback,
error: function(req, status, ex) {},
timeout:60000
});
};
this.find = function(id, callback) {
$.ajax({
type: 'GET',
url: this.myurl + '/' + id,
contentType: 'application/json',
success: callback,
error: function(req, status, ex) {},
timeout:60000
});
};
this.findAll = function(callback) {
//alert('sfindall');
//alert('myurl' + this.myurl);
$.ajax({
type: 'GET',
url: this.myurl,
contentType: 'application/json',
success: callback,
error: function(req, status, ex) {},
timeout:60000
});
};
this.remove = function(id, callback) {
$.ajax({
type: 'DELETE',
url: this.myurl + '/' + id,
contentType: 'application/json',
success: callback,
error: function(req, status, ex) {},
timeout:60000
});
};
this.loadTmpl = function(turl, callback) {
$.ajax({
url: turl,
success: callback,
error: function(req, status, ex) {},
timeout:60000
});
}}
var carRestServiceJs = new RestServiceJs('/rest/car');
// add update event
$("a.update_link").click(function() {
//alert('del' + this.id);
carRestServiceJs.find(this.id, function(data) {
//alert('update: ' + data);
loadAddModel(data);
//$("#modelName").val(data.name);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment