2

Hi I am loading a page using jquery .load() method.
the page is loaded perfectly on the firefox but it isn't load when I am opening the page on the google chrome.

Do you guys have some solution.

<script>
          var xmlHttp;
          function initAjax() {
              try {
                  xmlHttp = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
              } catch(e) {
                  try {
                      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
                  } catch(e) {
                      try {
                          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                      } catch(e) {
                          alert("No AJAX!?");
                          return false;
                      }
                  }
              }

              xmlHttp.onreadystatechange = function() {
                  if(xmlHttp.readyState == 4) {
                      document.getElementById('main_container').innerHTML = xmlHttp.responseText;
                  }
              }
          }

function updateAjax(mypage) {
            var t=mypage;
            //alert(t);
                  if(t=="")
                  {
                      //alert("Welldone");   
                  }
                  else
                  {
                      xmlHttp.open("GET", t, true);
                      xmlHttp.send(null);
                  }
          }

window.onload = function() {
              initAjax();
          }
        </script>

        <div id="main_container" style="position: relative;">

        </div>

        <script src="../js/jquery.min.js"></script>
        <script src="../js/bootstrap.min.js"></script>
        <script src="../js/docs.min.js"></script>
        <script src="../js/jRating.jquery.js"></script>

        <script type="text/javascript">
          $("#main_container").load("home.html");
        </script>
Jai
  • 74,255
  • 12
  • 74
  • 103
user3366155
  • 452
  • 1
  • 3
  • 16

2 Answers2

0

Here is your answer.. Try to use this..

 <script>
      var xmlHttp;
      function initAjax() {
          try {
              xmlHttp = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
          } catch(e) {
              try {
                  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
              } catch(e) {
                  try {
                      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                  } catch(e) {
                      alert("No AJAX!?");
                      return false;
                  }
              }
          }

          xmlHttp.onreadystatechange = function() {
              if(xmlHttp.readyState == 4) {
                  document.getElementById('main_container').innerHTML = xmlHttp.responseText;
              }
          }
      }

function updateAjax(mypage) {
        var t=mypage;
        //alert(t);
              if(t=="")
              {
                  //alert("Welldone");   
              }
              else
              {
                  xmlHttp.open("GET", t, true);
                  xmlHttp.send(null);
              }
      }

window.onload = function() {
          initAjax();
      }
    </script>

    <div id="main_container" style="position: relative;">

    </div>

    <script src="../js/jquery.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script src="../js/docs.min.js"></script>
    <script src="../js/jRating.jquery.js"></script>

    <script type="text/javascript">
     $(document).ready(function(){
      $("#main_container").load("home.html"); }); 
    </script>
Vijayakumar
  • 303
  • 4
  • 10
  • 1
    I had a similar problem. Try to host in the server and load. it will work fine. If you try to load the page from local chrome will not display it correctly. – Vijayakumar Mar 19 '14 at 04:42
0

The issue is just that .load() for local files is blocked by Chrome for security reasons. If you are using it on a server it works, given that all of the files originate from the same place.



To enable a working version locally, try:

In Mac OS X, quite Chrome, enter in Terminal:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files

In Windows, quite Chrome, enter in Command Prompt:

chrome.exe --allow-file-access-from-files

(Maybe you actually have to have the path... I don't think so. If so, you'll have to find it yourself.)

In Linux, quite Chrome, enter something like this into the terminal:

/usr/bin/google-chrome --allow-file-access-from-files
Joseph Hansen
  • 12,665
  • 8
  • 50
  • 68