我在我的应用程序中使用 Zepto
作为 jQuery
的替代品,当我意识到 $.ajax
时,我正在处理一项任务> 有错误处理程序,但其他方法如 $.post
、$.get
没有。
这可能是什么原因?
函数签名
$.post(url, [data], function(data, status, xhr){ ... }, [dataType])
$.get(url, [data], [function(data, status, xhr){ ... }], [dataType])
引用资料
最佳答案
根据您关于 $.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/