How to enable FancyBox only after receiving the server's response?

On the server in the absence of data giving the header 403 and the text of the error, it is necessary in the case of this error fail to open the FancyBox, and at the moment it (works only partially). The fact that there is a dark background, ie, fancybox starts executing and waits for server response, if 200 is all right, but in the case 403, there is a dark background. How to be?

here is the code:
(function($) {
 $(document).ready(function () {
 var $btn = $('[data-router="btn-fancyBox"]');

$btn.fancybox({
 "href": this.href
 "type": "ajax",
 "ajax": {
 "method": "POST",
 "data": $btn.data(),
 statusCode: {
 200: function() {
$.fancybox.open();
}
 403: function(e) {
$.fancybox.close();
 return $('.message')
 .message('start', e);
}
}
},
 maxWidth : 700,
 maxHeight : 500,
 fitToView : false,
 width : "100%",
 height : "100%",
 autoSize : false,
 closeClick : false,
 openEffect : 'none',
 closeEffect : 'none'
});
});
}(jQuery));
July 12th 19 at 16:48
1 answer
July 12th 19 at 16:50
Solution
I would try to first load the data a separate function to initialize the fancybox only in case of successful server response.
Yeah ))) I about it had not thought of that, already done =) - Bonita commented on July 12th 19 at 16:53

Find more questions by tags jQuery