0 Replies Latest reply on Jul 23, 2015 5:43 PM by tmorris000

    Data access from local AJAX/XML without CORS

    tmorris000

      Hi all, I've followed this guide (Chris Gannon - Loading XML via AJAX into Adobe Edge) to get AJAX/XML up and running in Adobe Edge but I am only able to get it displaying by doing two things.

       

      1. Using a full, local, home server path to the file. Instead of using just "sampleoutput.xml" or even a full path using "file://" I have to use the same path as the preview, "http://127.0.0.1:54321/_DRIVE_C_EVIRD_/test/publish/web/sampleoutput.xml"

                With a local path, I get this error:

      XMLHttpRequest cannot load file:///C:/test/publish/web/sampleoutput.xml. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

      2. Installing a browser extension to allow full CORS (Chrome: Allow-Control-Allow-Origin: * - Chrome Web Store)

                Without the extension, I get this error:

      XMLHttpRequest cannot load http://127.0.0.1:54321/_DRIVE_C_EVIRD_/test/publish/web/sampleoutput.xml. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

       

      Obviously, both of these are unacceptable solutions to the problem as this page will need to be deployed out to many different machines. In this case, the XML file will always be local so CORS theoretically shouldn't be necessary (please correct me if I'm wrong on that).

       

      So how can I read local data from a local path, natively in any modern browser?

       

      Thanks!

       

      full code

      var fromName;

      var toName;

      var messageField;

      var outputField = $(this.lookupSelector("xmlOutput"));

      var messageString;

       

      $.ajax({

        type: "GET",

        url: "http://127.0.0.1:54321/_DRIVE_C_EVIRD_/test/publish/web/sampleoutput.xml",

        dataType: "xml",

        success: function(xml) {

       

        fromName = $(xml).find('fromname').text();

        toName = $(xml).find('toname').text();

        messageField = $(xml).find('message').text();

        messageString = "Hi " + toName + "<br>" + messageField + "<br> Lots of love from " +fromName;

        outputField.html(messageString);

        },

        error: function(xml) {

        alert('error reading xml');

        }

        });