gpt4 book ai didi

javascript - Zepto 的 $.post 没有错误处理程序

转载 作者:行者123 更新时间:2023-11-30 08:33:28 26 4
gpt4 key购买 nike

我在我的应用程序中使用 Zepto 作为 jQuery 的替代品,当我意识到 $.ajax 时,我正在处理一项任务> 有错误处理程序,但其他方法如 $.post$.get 没有。

这可能是什么原因?

函数签名

$.post(url, [data], function(data, status, xhr){ ... }, [dataType])

$.get(url, [data], [function(data, status, xhr){ ... }], [dataType])

引用资料

  1. > $.ajax
  2. > $.post
  3. > $.get

最佳答案

根据您关于 $.get$.post 的问题。是的,source code on github回答说此方法没有错误处理程序,但您可以在 $.ajaxSettings

中添加常见的错误处理程序

但是 最好使用 Zepto deferred API 而不是带有回调的 $.ajax .您必须包括 it manually .

它提供了$.Deferred promises API。取决于“回调”模块。包含时,$.ajax() 支持用于链接回调的 promise 接口(interface)。

使用 deferred 你可以捕获 deferred/promise 链中的错误:

$.post(/*any options*/).done(/*success handler*/).fail(/*error handler*/)

$.post().then(function() {
// success code here
}, function() {
// error code here
});

关于javascript - Zepto 的 $.post 没有错误处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34543351/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com