requestCatchUp(function(data) {
console.log(data);
});
function requestCatchUp(success, error) {
proxyRequest('open', function() {
this.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status >= 200 && this.status < 400) {
if (success) {
var data = (function() {
try {
return JSON.parse(this.responseText);
} catch (err) {
return this.responseText;
}
}.bind(this))();
success.call(this, data);
}
} else {
if (error) error.call(this);
}
}
};
return this;
});
}
function proxyRequest(method, callback) {
(function(native) {
XMLHttpRequest.prototype[method] = function() {
native.apply(callback.apply(this, arguments), arguments);
};
})(XMLHttpRequest.prototype[method]);
}
global: true (по умолчанию)
ajaxCatchUp().then(function(data) {
console.log(data);
});
function ajaxCatchUp() {
var promise = $.Deferred();
$(document).on('ajaxComplete', function(event, jqXHR) {
jqXHR.done(promise.resolve).fail(promise.reject);
});
return promise;
}
<button data-show-button="myBlock">Показать все</button>
<div data-show-block="myBlock" style="display:none">
{custom category="1,2,3" template="shortstory" order="title" sort="desc" from="15"}
</div>
$.each($('[data-show-block]'), function() {
if ($(this).children().length <= 15) {
var id = $(this).attr('data-show-block');
$('[data-show-button="'+ id +'"]').hide();
}
});
$('[data-show-button]').on('click touch', function(event) {
event.preventDefault();
var id = $(this).attr('data-show-button');
$('[data-show-block="'+ id +'"]').show();
$('[data-show-button="'+ id +'"]').hide();
});
.owl-carousel .item { transform: scale(1.005); }
<button data-show-ajax=".block">Показать все</button>
<div class="block" style="display:none">
{custom category="1,2,3" template="shortstory" order="title" sort="desc" from="15"}
</div>
$('[data-show-ajax]').on('click touch', function(event) {
event.preventDefault();
$($(this).attr('data-show-ajax')).show();
$(this).hide();
});
$.ajax({
url: url,
// Нужно указать тип передаваемых данных, параметр contentType: 'application/json'
data: data,
// тип ответа от сервера нужно писать в lowerCase: json
dataType: 'JSON',
// Параметр type устарел для версий выше 1.9, используйте параметр method
type: type || 'POST',
cache: false
});
Можно так:
if ($('#checkAddress').prop('checked')) {}