Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8084/cron4jsnmp_1_os/. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
I tried a Sample JQuery code, in order to load a JSP file in a <div> from a static HTML file.
The Sample code is here
https://gist.github.com/sourcecodemart/8472642
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Load</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function(){
jQuery('#loadPage').click(function(){
jQuery('#pagecontainer').load('http://localhost:8084/cron4jsnmp_1_os',
function(){alert('Content Successfully Loaded.')}
);
});
})
</script>
</head>
<body>
<a href="javascript:void(0)" id="loadPage">Click To Load Web Page</a><br />
<div id="pagecontainer" />
</body>
</html>
When I run this code, I got the following error in FireBug Console
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8084/cron4jsnmp_1_os/. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
If We try to load a URL from Servlet, the following work around is required to be done at Servlet level. This Solution worked for me and I was able to load JSP file in a HTML File from my local file system
I tried a Sample JQuery code, in order to load a JSP file in a <div> from a static HTML file.
The Sample code is here
https://gist.github.com/sourcecodemart/8472642
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Load</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function(){
jQuery('#loadPage').click(function(){
jQuery('#pagecontainer').load('http://localhost:8084/cron4jsnmp_1_os',
function(){alert('Content Successfully Loaded.')}
);
});
})
</script>
</head>
<body>
<a href="javascript:void(0)" id="loadPage">Click To Load Web Page</a><br />
<div id="pagecontainer" />
</body>
</html>
When I run this code, I got the following error in FireBug Console
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8084/cron4jsnmp_1_os/. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
If We try to load a URL from Servlet, the following work around is required to be done at Servlet level. This Solution worked for me and I was able to load JSP file in a HTML File from my local file system
response.addHeader("Access-Control-Allow-Origin", "*");
Reference:
http://stackoverflow.com/questions/20881532/no-access-control-allow-origin-header-is-present-on-the-requested-resource
No comments:
Post a Comment