I'm struggling to find a solution for the cross-domain issue in my code:
$apiUrl = 'https://gtmetrix.com/api/0.1/test';
$apiUser = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2a8ada755e4b3afb5bcb9acabb3b6edb0bcd7adaf">[email protected]</a>';
$apiKey = '1234567890';
$requestUrl = 'http://converge.io';
function FetchCtrl($scope, $http, $templateCache) {
$scope.method = 'post';
$scope.url = $requestUrl;
$scope.fetch = function() {
$scope.code = null;
$scope.response = null;
$http({method: $scope.method, url: $apiUrl + '?login-user=' + $apiUser + '&login-pass=34bcb5c46bc6d5fb18a8552820027eb9' + '&url=' + $scope.url, cache: $templateCache}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
$scope.fetch();
$scope.updateModel = function(method, url) {
$scope.method = method;
$scope.url = url;
};
}
The error message I am receiving is:
XMLHttpRequest cannot load https://gtmetrix.com/api/0.1/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b2c6d7c1c68ddeddd5dbdc9fc7c1d7c08fd8ddd7f2c4d3dcd6dbd5c0ddc7c29cd1dddf">[email protected]</a>&login-pass=1234567890&url=http://converge.io. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://converge' is therefore not allowed access.
It seems like I need to include the following line, but I can't seem to make it work:
delete $http.defaults.headers.common['X-Requested-With'];