Почему бы не использовать $ .ajax вместо $ .get. Более четкая версия. Помните: $ .get - это всего лишь оболочка $ .ajax. Внутренне $ .ajax всегда вызывается. Какое преимущество $ .ajax дает то, что оно более настраивается, чем $ .get и $ .post.
$.ajax({
type: "GET",
url: "/amodel/list2",
success: function (r) {
//Do stuff here. This will only execute when request succeed
//r in function parameter is response
},
error: function (r, textStatus, errorThrown) {
//i am using this error handler in ajax method to get
//the status code in my project. hope this will work for you as well
if (r.status === 403) {//do stuff}
if (r.status === 470) {}
}
}).fail(function (e) {
console.log(e.responseText);
}).always(function () {
//Do stuff here which you want always to execute.
// Like hiding ajax loader even if request fails etc
});
Any
- это метод расширения IEnumerable<T>
, который ICollection
не реализует (но ICollection<T>
делает). Если вы можете получить ICollection<T>
, вы можете использовать его; в противном случае вы можете написать свой собственный эффективный Any
(работает так же, как версия .NET, с настройкой производительности .NET Framework не имеет, но имеет .NET Core):
Примечание: фрагмент ниже используется более старая версия языка C #, поскольку неизвестно, какова базовая линия.
public class Extensions
{
public static bool Any(this IEnumerable source)
{
if (source == null) throw ArgumentNullException(nameof(source));
// Performance tweak to eliminate allocation of enumerator if we have a count.
if (source is ICollection) return ((ICollection)source).Count > 0;
IEnumerator e = source.GetEnumerator();
bool any = e.MoveNext();
// Make sure the enumerator is properly disposed of if necessary.
// IEnumerator<T> implements IDisposable but an implementation of IEnumerator itself might.
if (e is IDisposable) ((IDisposable)e).Dispose();
return any;
}
}