I have huge problem with loading xml
file from assets
path by jQuery
mobile in phonegap project.
I need to load an xml
file. File is placed in the root of my project. Problem is with ajax url: "language.xml". Here is my code:
var language = 'english';
var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/;
$.ajax({
url: "language.xml",
success: function(xml) {
$(xml).find('translation').each(function(){
var id = $(this).attr('id');
var text = $(this).find(language).text();
if(text.match(regEx)){
$("." + id).replaceWith('<a href="mailto:'+text+'" data-role="button" data-inline="true" data-theme="d" rel="external" data-mini="true">'+text+'</a>');
}
else{
$("." + id).html(text);
}
});
}
});
When I use the absolute path, I am able to load this file adding url: file:///android_asset/www/language.xml
This is good only for Android assets. But I need the correct path for iOS too.
UPDATE Code above is correct. Fail was in testing within the desktop browser. Project works fine on Android and iOS with relative paths.
There's no need to add absolute path like file:///android_asset/www/
for Android or file:///var/mobile/Applications/7D6D107B-D9DC-479B-9E22-4847F0CA0C40/YourApplication.app/www/
for iOS .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With