Skip to content

Instantly share code, notes, and snippets.

@djanix
Last active August 29, 2015 14:02
Show Gist options
  • Save djanix/de465f147c8d0e44ea29 to your computer and use it in GitHub Desktop.
Save djanix/de465f147c8d0e44ea29 to your computer and use it in GitHub Desktop.
jquery ajax call
function loadItems(url, params, callback) {
$.ajax({
url: url,
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify(params),
type: 'POST'
})
.done(function (data, textStatus, jqXHR) {
var result = ((typeof data) == "string") ? $.parseJSON(data) : data;
return callback(null, result);
})
.fail(function (jqXHR, textStatus, errorThrown) {
return callback(['fail', errorThrown], null);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment