Reputation: 101
I am developing an app via phonegap and I must read an external xml file which have a lot of important information for my app.
I tried the code below, but I am getting an annoying error. After searching everywhere I did not find any solutions.
The jquery code:
$(document).ready(function(){
$.ajax({
url: 'http://servicos.cptec.inpe.br/XML/cidade/233/condicoesAtuaisUV.xml',
success: function(data) {
console.log('ok')
},
error: function() {
console.log('problem')
}
});
});
The damm error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://servicos.cptec.inpe.br/XML/cidade/233/condicoesAtuaisUV.xml. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
I read that it is necessary to enable CORS, but how do I do that?
Thanks for the attention!
Upvotes: 0
Views: 450
Reputation:
On Phonegap, you need to use a white list to access more than one server. The CORS advice you are getting is the correct theme, but not the correct solution - for phonegap.
NOTE: read carefully on this. Many people have been tripped up. There is a difference. As of this month (July 2015), versions after 4.0 and leading edge version will REQUIRE a plugin. (I don't have all the correct details on this, so you'll have to read.)
Whitelist Guide 4.0
http://docs.phonegap.com/en/4.0.0/guide_appdev_whitelist_index.md.html
Whitelist Guide 3.3
http://docs.phonegap.com/en/3.3.0/guide_appdev_whitelist_index.md.html
Some details here:
http://community.phonegap.com/nitobi/topics/which-whitelist-plugin-should-pgb-user-to-use
http://community.phonegap.com/nitobi/topics/pgb-support-which-whitelist-function
Upvotes: 1