I came across an error on getting the url meta data by using Angular JS with ajax.
The error statement is:
XMLHttpRequest cannot load http://www.esample.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
var app = angular.module('myapp', []);
app.controller('ctrl',
function ($scope,$http){
$http.get('http://example.in/')
.success(
function(data,status,headers,config){
var details = [
{title:$(data).filter('title'),
description:$(data).filter('meta[name=description]').attr("content"),
keywords:$(data).filter('meta[name=keywords]').attr("content"),
image:$(data).filter('meta[name=og:image]').attr("content")},
];
$scope.details;
})
.error(function (data, status, headers, config) {
$scope.error = " - Something went wrong with your code....";
});
});
What I have tried:
$http.get('http://example.in/', function (res) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
})...
Reference:
access to specific domain only.