3

I am trying to open and read an XML file from Phonegap but having this CORS error. How can I resolve this?

XMLHttpRequest cannot load file://localhost/../data/file.xml. Origin null is not allowed by Access-Control-Allow-Origin.

The caller code is:

var request = $.ajax({
    type: "GET",
    url: "data/file.xml",
    async: false,
    dataType: "xml"
  });

I also have this snippet in my code due to the explanation here:

$(document).on( "mobileinit", function() {

           $.support.cors = true;
           $.mobile.allowCrossDomainPages = true;

           });
fab
  • 317
  • 4
  • 20
noway
  • 2,585
  • 7
  • 41
  • 61

1 Answers1

1

You need to mod your phonegap settings to allow access to localhost

Theres a few files to look at so see this gist and other stackoverflow post.

Note those examples are for Android; with iPhone its the same issue, just different files.

Community
  • 1
  • 1