Jquery具有语法beforeSend
,并且在获取API或JSON时已完成。香草javascript(ES6或ES7)是否提供像beforeSend
和Completed
这样的语法?还是可以帮助我使用现代javascript在jquery中创建像beforeSend一样的内容?
$.ajax({
type: 'POST',
url: url,
data: data,
beforeSend: function() {
// setting a timeout
$(placeholder).addClass('loading');
},
success: function(data) {
if (append) {
$(placeholder).append(data);
} else {
$(placeholder).html(data);
}
},
error: function(xhr) { // if error occured
alert("Error occured.please try again");
$(placeholder).append(xhr.statusText + xhr.responseText);
$(placeholder).removeClass('loading');
},
complete: function() {
$(placeholder).removeClass('loading');
},
dataType: 'html'
});