I have a $.getJSON call that populates a collection by making a Web API call :
$.getJSON("/api/rating", self.ratings);
How would I rewrite this if I want to add some of the options found in $.ajax such as beforeSend, data, success etc?
EDIT : I have tried both of these and none of the alerts are hit :
$.getJSON("/api/rating")
.beforeSend(function (xhr) {
alert("before");
$('#divLoading').addClass('ajaxRefresh');
xhr.setRequestHeader('X-Client', 'jQuery');
})
.success(function (result) {
alert(result);
self.ratings = result;
})
.complete(function (result) {
alert("complete");
$('#divLoading').removeClass('ajaxRefresh');;
})
.error(function () {
alert("error");
});
$.getJSON("/api/rating", self.ratings)
.beforeSend(function (xhr) {
alert("before");
$('#divLoading').addClass('ajaxRefresh');
xhr.setRequestHeader('X-Client', 'jQuery');
})
.success(function (result) {
alert(result);
self.ratings = result;
})
.complete(function (result) {
alert("complete");
$('#divLoading').removeClass('ajaxRefresh');;
})
.error(function () {
alert("error");
});
$.getJSON is a shorthand for:
So your sample could translate into:
etc.