Reputation: 5994
Cannot figure out how to get around cross domain issue. My code:
$apiUrl = 'https://gtmetrix.com/api/0.1/test';
$apiUser = '[email protected]';
$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:
XMLHttpRequest cannot load https://gtmetrix.com/api/0.1/[email protected]&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 that I need to include the following but cannot get it to work:
delete $http.defaults.headers.common['X-Requested-With'];
Upvotes: 1
Views: 5049
Reputation: 3949
I think there is a workaround for this. Here is the logic
So instead of calling gtmetrix with your xhttprequest, try calling the script you've done.
Upvotes: 2