Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
How to resolve the " access-control-allow-origin " error?
Guruprakash C
Feb 9 2017 3:49 AM
267
Reply
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
.
Attachment:
metadetailsAngularJS.zip
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to create array using two values
Regarding Page Navigation from Menu.