owl carousel json not working

Solutions on MaxInterview for owl carousel json not working by the best coders in the world

showing results for - "owl carousel json not working"
Ella
16 Jan 2018
1var OC = $("#owl-demo-featured").owlCarousel({
2    path : 'path/to/json',
3    onSuccess : function(r){
4        if( r.length > 0 ){
5
6            for( var i in r ){
7                if( r.hasOwnProperty(i) ){
8                    var $html = '';
9                    // process you data with the template you want inject
10                    OC.trigger('add.owl.carousel', jQuery($html) )
11                }
12            }
13            OC.trigger('refresh.owl.carousel')
14        }
15    },
16    onError: function(r){
17        console.error(r);
18    }
19});
20
Catarina
07 Oct 2019
1/**
2 * Owl Carousel JSON load plugin
3 * @since 2.0.0
4 * @author maksbd19 
5 * @link http://stackoverflow.com/questions/35838983/
6 */
7
8;(function ( $, window, document, undefined ) {
9
10    var Insatances =  undefined;
11
12    var JSONload = function(carousel){
13
14    this._core = carousel;
15
16    this.options = {};
17
18    this._handlers = {
19        'initialized.owl.carousel': $.proxy(function(e) {
20            if (!e.namespace || !this._core.settings || !this._core.settings.path) {
21                return;
22            }
23
24            Insatances = Insatances || [];
25
26            if( !pathExists(this._core.settings.path, Instances) ){
27                Instances.push({
28                    path: this._core.settings.path,
29                    onSuccess: this._core.settings.onSuccess,
30                    onError: this._core.settings.onError,
31                    loading: false
32                });
33            }
34
35            for( var i in Instances ){
36                if( Instances.hasOwnProperty(i) && Instances[i].path != '' && !Instances[i].loading ){
37
38                    Instances[i].loading = true;
39
40                    $.getJSON(Instances[i].path, $.proxy(function (data) {
41                        if (typeof Instances[i].onSuccess === "function") {
42                            Instances[i].onSuccess.call(this, data);
43                        }
44                    }, this)).fail($.proxy(function (data) {
45                        if (typeof Instances[i].onError === "function") {
46                            Instances[i].onError.apply(this, [data]);
47                        }
48                    }, this));
49                }
50            }
51
52            function pathExists(path, instance){
53                if(instance.length == 0){
54                    return false;
55                }
56                for( var i=0; i<instance.length; i++ ){
57                    if( instance[i].path == path ){
58                        return true;
59                    }
60                }
61
62                return false;
63            }
64
65        }, this)
66    };
67
68    this.options = $.extend(JSONload.Defaults, this._core.options);
69    this._core.$element.on(this._handlers);
70}
71
72JSONload.Defaults = {
73    path: '',
74    onSuccess:'',
75    onError:''
76};
77
78$.fn.owlCarousel.Constructor.Plugins['JSONload'] = JSONload;
79})( window.Zepto || window.jQuery, window,  document );
80