cordova-HTTP: ReferenceError: Can't find variable: cordovaHTTP

I installed the plugin and used it in index.js. Whenever I try to make another request fro another file I keep getting ReferenceError: Can’t find variable: cordovaHTTP. I have included cordova.js in years.html file

years.js var years = {

showYears:function(){
    var categoriesDiv = $("#cat");
    categoriesDiv.html(window.sessionStorage.getItem('key'));
    alert(window.sessionStorage.getItem('key'))
    years.getYears();
},

getYears: function(){
    cordovaHTTP.get("http://localhost/arableague/public/api/getYears/",
                    {
        id:2
    },
                    {},
                    function(response){
        alert(response);
        var yearsResult = JSON.parse(response.data);
        var yearsDiv = $("#yearsDiv");
        alert('x')
        for(i=0; i<yearsResult.length; i++){
            var cat = yearsResult[i]['year'];
            var button = '<button>'+ cat +'</button>';

            console.log(button);
            yearsDiv.append(button)
        }
    },
                   function(response){
        alert(response.error);
        })
}

};

About this issue

Most upvoted comments

@mentatzoe I had the same issue, on Android 4.4 and below but was working fine on the Android 5.x and above devices. I was using window.cordovaHTTP, I commented out the whole if(typeof angular != undefined) and just retained the else part and now works on all devices. Hope this helps.

Cordova plugin background model did not solve the problem. https://github.com/SidharthPHariharan/cordova-HTTP solved the problem