我有很多$.post
,$.ajax
调用,它们都返回一个JSON数组。我意识到有时我必须检查状态代码,例如检查用户是否被删除。多数民众赞成,但现在我必须对所有事件进行状态检查。通过accindent,我不能以某种方式设置默认回调?
答案 0 :(得分:1)
您可以使用AJAX的beforesend方法
beforeSend: function (xhr) {
// It will fired each just before each AJAX request
}
答案 1 :(得分:1)
let tempDBObject = self.petListArray[indexPath.row] as! Database
cell?.petName.text = tempDBObject.Hname
//Doc Path
let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first! as String
let imagePath = String("\(documentDirectory)/\(tempDBObject.Hpath!)")
if imagePath == "" {
}else{
cell?.petImageView.image = UIImage(contentsOfFile: imagePath)
}
答案 2 :(得分:1)
您可以使用: -
描述:在Ajax请求之前附加要执行的函数 已发送。这是一个Ajax事件。每当要发送Ajax请求时,jQuery都会触发ajaxSend事件。已经使用.ajaxSend()方法注册的任何和所有处理程序都会在此时执行。
.ajaxSend(处理程序)
类型:功能(事件事件,jqXHR jqXHR, PlainObject ajaxOptions)要调用的函数。
用法: -
$(document).ajaxSend(function( event, jqxhr, settings ) {
// This will be fired before all ajax requests
});
注意强>
如果在$.ajax()
选项设置为$.ajaxSetup()
的情况下调用global
或false
,则.ajaxStart()
方法将不会触发。