ES6 Vanilla JS中的JQuery BeforeSend相等

时间:2019-01-20 23:00:43

标签: javascript jquery ecmascript-6 fetch axios

Jquery具有语法beforeSend,并且在获取API或JSON时已完成。香草javascript(ES6或ES7)是否提供像beforeSendCompleted这样的语法?还是可以帮助我使用现代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'

});

0 个答案:

没有答案