Search code examples
javascriptajaxaccess-denied

Getting Access Denied in an ajax application while testing locally


I've only started reading up on development using ajax, and was testing the webpage in my local machine. All that the page contains is couple of lines of html, javascript, css and of course the request objects etc for ajax.

I was trying this - on page1.html, if you click on tab1 (an icon) in it, it should load a page named "page2.html" into the content div under the tab1 in page1.html (sort of like a frame). I was using ajax for this, something roughly like:

 var url= "page2.html";
 request.open("GET", url, true);
 request.onreadystatechange = displayResult;
 request.send(null);

So basically, clicking on the tab1 icon in page1 would load page2 into a portion of the page1, using ajax. On running, it ran into an error saying Access denied, with line referring to the request.open().

I know that giving url = "page2.html" will not suffice.

Question -

  1. How do i mention the full url here so that it can fetch the contents of page2.html (which resides in the same folder, locally, as the script and page1.html)
  2. I would like to test the pages that i code, locally on my machine. From the above issue, i assume that testing ajax on a local machine is not a good idea. Is this right? DO i have to test it on a server?

Solution

  • you can't get content of local files with XMLHttpRequest, except your modify configuration of your Browser:

    in Opera on "about:config" page:

    enable "Allow File XMLHttpRequest"