javascript - Retrieve text from page with jQuery -


i'm trying retrieve text remote url , put in div on current page. first i'm trying text local file first, doesn't seem pull text. suggestions?

<!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <title>html5 jquery</title>     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>  </head> <body>     <div id="replace">         placeholder     </div>      <script type="text/javascript">         $(document).ready(function(){             $.get("test.txt", function(data) {                 $("#replace").html(data);                 }             );         });     </script> </body> </html> 

same origin policy prevents page reading in javascript page coming origin (roughly domain+port).

a special case 1 of file:// protocol : files opened in protocol considered different origins.

that's why must use http server test ajax code.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

angularjs - ng-repeat duplicating items after page reload -

javascript - What's causing this slow/delayed audio playback in Safari? -