我会注意到这段代码并不是我自己构建的,我只是在已经存在的系统上使用插件来做一些UI更改。
我正在构建一个插件,它利用了blockUI(是的,我需要使用插件构建一个插件),以便在触发Ajax调用时在某些元素上显示加载图标,但是这个特别调用alert()
如果success()
事件没有得到所需的响应。
这样做的结果是我的加载图标调用后的alert
火灾,这是不是我想要做的事。
当我打电话我建立的功能,我通过在$.post()
完成我需要的设置和选项,比如:
$.fn.startLoading({
element: $("div"),
ajax: $.post('some.url',
{
//Ajax settings...
}, function (response) { //This is the success function, right?
if (good) {
//stuff
}
else
alert("Bad!"); //This happens BEFORE fadeOut()
}
}, 'text')
.error(function (msg) {
alert('Worse error!');
})
});
我的插件的功能通吃的这种作为一个options
参数,像这样:
$.fn.startLoading = function (options) { ...
我再访问$.post()
电话这样的:
if (options.ajax)
ajax = options.ajax;
这是我卡住的地方。我需要确保发生在success
事件触发之前。我如何使用我在插件中创建的ajax
变量来做到这一点?
语法错误在这里:'ajax:$ .post('some.url'),{'should should remove')' –
刚才看到了,谢谢。现在更新。 – Kehlan
此外,'jqXHR.error'折旧,您应该使用.fail。 –