Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap CORS issue

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;

           });
like image 973
noway Avatar asked Aug 10 '26 00:08

noway


1 Answers

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.

like image 155
James Hornitzky Avatar answered Aug 13 '26 04:08

James Hornitzky