我只想在jquery ajax调用完全完成之后执行一个js函数(在成功和错误事件完成之后)。在ajax调用将传入的数据放入一个元素之后。
如何实现这一点。
发布于 2011-11-26 00:10:22
您可以使用对任何jQuery AJAX方法的回调来延迟另一个函数的执行,直到请求完成。
示例:
$.post('/some/url', somedata, function() {
// put the code you want to execute on completion here
});对于更复杂的场景,使用实际的ajax方法,它为您提供了成功、完成、错误和其他事件的挂钩。通常,您只需要成功和错误。
$.ajax( '/some/url', {
data: somedata,
type: 'post',
success: function(result) {
// success code execution here
},
error: function(xhr,status,error) {
// error code here
},
complete: function(xhr,status) {
// completion code here
}
});https://stackoverflow.com/questions/8271618
复制相似问题