javascript - No 'Access-Control-Allow-Origin' header is present on the requested resource in jQuery load and iframe -
when use load html content of website using
$('.myclass').load('https://www.google.com');
or use iframe , access data of google.com gives access-control-allow-origin error.
code :
$(document).ready(function() { $('#root').load('http://www.google.com/');// cross origin error $('#theframe').contents() // cross origin error }); <!doctype html> <html> <head> <meta http-equiv="access-control-allow-origin" content="*"> <title>demo</title> <script type="text/javascript" src="static/javascript/jquery-3.1.1.js"></script> </head> <body> <div id="root"></div> <iframe id="theframe" src="http://www.google.com/" style="width:100%;" frameborder="0"> </iframe> </body> </html> error :
xmlhttprequest cannot load google. no 'access-control-allow-origin' header present on requested resource. origin 'localhost' therefore not allowed access.
you can end run around proxy. https://cors.now.sh/
$(document).ready(function() { $('#root').load('https://cors.now.sh/http://www.google.com/'); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="root"></div>
Comments
Post a Comment