Cannot read property 'protocol' of undefined Cannot read property 'protocol' of undefined ajax ajax

Cannot read property 'protocol' of undefined


You're issuing a malformed $http request.

You are not supposed to set your headers in a separate call to $http. Call to $http() will actually issue the request, but since you configured it with just the header (no url or method), it throws that error at you (as expected).

If you want to set your header you'll want to do that by passing a custom config object as a second parameter to your $http.get() call:

$http.get(url, {  headers: {    'Content-type': 'application/json'  }}).success(function (events) {  $scope.events = events;});


This error occurs when something goes wrong in request, for ex. if you set url as undefined, invalid method, or invalid content type, anything wrong with request object will throw this error.


Got the same Issue calling an API from react.After checking my code I saw the endpoint from the environment file could not be found which led to the error.

All I did to fix it was to stop and restart the react app