是否有预先发送的 Javascript 承诺? [英] Is there a beforesend Javascript promise?

查看:41
本文介绍了是否有预先发送的 Javascript 承诺?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用脚本将数据发送到谷歌驱动器.该脚本有两个函数来检测请求何时发送.是否有替代 jquery 的函数 beforesend?

I am using a script to send data to google drive. The script has two functions to detect when the request was sent or not. Is there a function alternative to jquery beforesend?

检测请求正在发送?

fetch(scriptURL, { method: 'POST', body: new FormData(form)})  
         .then((response) => {
               alertify.success("Sent succesfully");
            })
             .catch((err) => {
                alertify.error("Failed to send");
            });

推荐答案

不,没有,但您可以将其包装在您自己的函数中,以便在任何地方使用.

No there's not, but you can wrap it in your own function that you use everywhere.

function myFetch() {
    console.log('about to send');
    return fetch.apply(this, arguments);
}

 myFetch('/echo').then(e => console.log(e));

这篇关于是否有预先发送的 Javascript 承诺?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆