Home Why is my code throwing [$http:badreq] error?
Reply: 2

Why is my code throwing [$http:badreq] error?

Abhinav Alok
1#
Abhinav Alok Published in 2018-01-12 15:55:28Z

I am trying to fetch some JSON data using the given URL. I can't understand why it's not working. I went through angular docs and other resources but as I am new to angular, am finding it difficult to find out the error. Can someone help me, please?

My code.

var app = angular.module('mainApp', []);

app.controller('mainController', ['$http', function ($http){
var self = this;


this.matches = [];
console.log(this.matches);

this.basrUrl = "https://raw.githubusercontent.com/openfootball/football.json/master/2015-16/en.1.json";

this.loadAllMatches = function(){   
    $http({
        method: "GET",
        url: self.baseUrl,
    }).then(function successCallback(response){
        console.log(response);
        self.matches = response.data.matches;
        console.log(self.matches);

      },function errorCallback(response){
        alert("Some Error occurred, check the console");
        console.log(response);

      });
    }   
}]);
Ezekiel
2#
Ezekiel Reply to 2018-01-12 15:58:04Z

Because it is probably not getting the right baseUrl, confirm that the self.baseUrl returns an actual link because you probably misspelled. this.basrurl and self.baseurl

UncleDave
3#
UncleDave Reply to 2018-01-12 15:58:48Z

Simple typo:

this.basrUrl = "https://raw.githubusercontent.com/openfootball/football.json/master/2015-16/en.1.json";

basrUrl

Actual usage:

url: self.baseUrl

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30867 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO