TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guruprakash C
NA
142
27.7k
How to resolve the " access-control-allow-origin " error?
Feb 9 2017 3:49 AM
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
Reply
Answers (
1
)
How to create array using two values
Regarding Page Navigation from Menu.