none
Load local files using XMLHttpRequest

    Question

  • Hi,

    I'm trying to load local files (ex.: file:///D:/source.html) using XMLHttpRequest and window.ActiveXObject("Microsoft.XMLHTTP"). When I use ActiveXObject files loads correctly. But when I use XMLHttpRequest I got error 'Error: Access is denied.'

    Why?

    I got this issue while create Windows Phone app using Cordova and jQuery 2.0.

    Monday, October 07, 2013 1:15 PM

Answers

All replies

  • I'm trying to load local files (ex.: file:///D:/source.html)

    Try serving them from HTTP instead.  E.g. host HTML on IIS locally.



    Robert Aldwinckle
    ---

    Monday, October 07, 2013 11:57 PM
  • The issue is exactly loading local files.
    Tuesday, October 08, 2013 7:17 AM
  • Hi,

    Please provide source.html

    regards.


    Rob^_^

    Tuesday, October 08, 2013 11:15 PM
  • index.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>jQuery Local Ajax</title>
        <!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>-->
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.js"></script>
        <script>
            $(function() {
                $.ajax({
                    url: "file:///D:/source.html",
                    isLocal: true,
                    dataType: "html"
                }).done(function(data) {
                    $("body").append(data);
                }).fail(function(jqXHR, textStatus, errorThrown) {
                    console.log(jqXHR);
                    console.log(textStatus);
                    console.log(errorThrown);
                });
            });
        </script>
    </head>
    <body>
    
    </body>
    </html>

    source.html

    <p>Hello world!</p>

    Wednesday, October 09, 2013 10:12 AM
  • Hi,

    f12>Console tab, refresh page to show suppressed error messages.

    (tip: remove the console.log code from your pages before releasing into production... IE9 and lower throw an exception if the Developer tool is not visible when the console object is called.... choose the Break on all errors debug option to show thrown errors from jQuery)

    Test in other browsers...All other browsers prevent cross-origin requests also.

    "Origin null is not allowed by Access-Control-Allow-Origin"

    check chrome:flags to see if you have turned off any experimental features of Chrome/Webkit.


    Rob^_^

    Wednesday, October 09, 2013 11:24 PM
  • Hi,

    f12>Console tab, refresh page to show suppressed error messages.

    (tip: remove the console.log code from your pages before releasing into production... IE9 and lower throw an exception if the Developer tool is not visible when the console object is called.... choose the Break on all errors debug option to show thrown errors from jQuery)

    Test in other browsers...All other browsers prevent cross-origin requests also.

    "Origin null is not allowed by Access-Control-Allow-Origin"

    check chrome:flags to see if you have turned off any experimental features of Chrome/Webkit.


    Rob^_^

    The issue is about IE. Not chrome.
    Thursday, October 10, 2013 7:14 AM
  • Hi,

    It does not work in other browsers also.

    I suppose that what's xmlhttprequest means.


    Rob^_^

    Saturday, October 12, 2013 4:03 AM