Web API 呼び出しを行うことでコレクションに値を設定する $.getJSON 呼び出しがあります。
$.getJSON("/api/rating", self.ratings);
$.ajax にある beforeSend、data、success などのオプションを追加したい場合、これをどのように書き直せばよいでしょうか?
編集:私はこれらの両方を試しましたが、アラートはどれもヒットしません:
$.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");
});