0
I have a javascript/jquery code that saves a new one on my system, in this code I want that when the request fails to be executed a notification plug-in, I wanted to pass to this plug-in the data of jqXHR, textStatus, errorThrown
of the method .fail()
without having to put in the scope of the plug-in like this $('.wrapper').notify(jqXHR, textStatus, errorThrown);
$(function(){
$.ajaxSetup({
type: "post",
dataType: "json",
beforeSend: function(){
$.loader('show');
},
complete: function(){
$.loader('hide');
}
});
$('.js-anotacao').on('click',function(e){
e.preventDefault();
var selct = $(this);
var forms = selct.closest('form');
var dados = forms.serialize();
$.ajax({
data: dados,
url: $.path() + "api/RegisterLog.php",
success: function (response) {
console.log(response);
}
}).fail(function( jqXHR, textStatus, errorThrown ) {
$('.wrapper').notify();
});
});
});
This is the initial code of the plug-in:
(function ($) {
// valores padrões da aplicação
var _defaults = {
background : "green",
type : "success",
color : "white"
}
// executa o código quando houver seletor
$.fn.notify = function(options) {
var settings = $.extend(true, {}, _defaults, options);
var container = $(this);
if (jqXHR) {
// faz alguma coisa
}
console.log(jqXHR);
}
})(jQuery);
What problem are you encountering? The code when you run and fail does not enter fail()?
– Alexis Garcia
No, that’s not the problem. I’m making a plugin for notifications and query pass to them the values of
jqXHR, textStatus, errorThrown
without having to put like this$('.wrapper').notify(jqXHR, textStatus, errorThrown);
– Helison Santos