0

I have 2 HTML files

File 1. index.html
File 2. nav_bar.html

Here I am trying to load static page nav_bar.html into index.html

I tried one of the jquery load method - sample code of index.html. ie.

<script type="text/javascript">
    $(function() {
       $("#nav_bar").load("nav_bar.html"); 
    });
</script>

Working fine with Firefox but Chrome does not response to load this file. I am not getting the way to resolve it. Note: Please avoid the use of iframe.

Thanks in advance.

Rory McCrossan
  • 306,214
  • 37
  • 269
  • 303
Rubyist
  • 6,247
  • 8
  • 46
  • 83
  • There is no reason that would not work in Chrome. What error did you get? – Rory McCrossan Jun 05 '14 at 07:35
  • NO such error, it does not load that partial. – Rubyist Jun 05 '14 at 07:36
  • What about using HTML imports: http://www.html5rocks.com/en/tutorials/webcomponents/imports/ – inf3rno Jun 05 '14 at 07:37
  • Only shows nav_bar.html on html page and tried .html as well – Rubyist Jun 05 '14 at 07:39
  • I think the cause is that you are opening the file (index.html) directly into the browser (chrome) and not using a server or apache or something like that? – dunli Jun 05 '14 at 07:40
  • Yes, I am opening the file directly from folder rather than any server or apache. May be I will try by installing wamp or any server to see the effect. – Rubyist Jun 05 '14 at 07:45
  • Yes, you need to run it on a webserver. Chrome is blocking the request because you are attempting to access the file system of the local machine. – Rory McCrossan Jun 05 '14 at 07:48
  • Yes @RoryMcCrossan : Your are right. I tried to execute the same page in netbeans using default server. It is rendering the page perfectly. My bad to execute the page without server. Thanks a lot Guys ... – Rubyist Jun 06 '14 at 05:54

2 Answers2

0

Chrome enforces same origin policy. Read about it here.

Fetch html from server via ajax and load it as string.

Read more about it here

Community
  • 1
  • 1
avidenic
  • 624
  • 7
  • 17
0

For disabling same origin policy for chrome : Use Stackoverflow Post or this

Community
  • 1
  • 1
zafus_coder
  • 3,575
  • 2
  • 10
  • 13
  • Will this change, may raise any security concern ? – Rubyist Jun 05 '14 at 07:47
  • yeah thats a concern , For other avialble options kindly see what are other workarounds , [link] (http://usamadar.com/2012/06/24/getting-around-browsers-same-origin-policy-sop-with-proxies-script-injection-jsonp-and-cors/ ) .. I think Dynamically Inject the ‘src’ of a – zafus_coder Jun 05 '14 at 07:58
  • Thanks a lot .. @zafus – Rubyist Jun 06 '14 at 05:55