I am trying to localize my strings by creating an xml file for each language then using ajax get like so.
var text = new Object();
$.ajax({
async: false,
type: 'GET',
url: 'english.xml',
dataType: "xml",
error: function(xhr, status, error) {
console.log("Lets see the error...");
console.log(xhr.responseText);
},
success: function(xml){
$(xml).find('text').each(function(){
text[$(this).attr('id')] = $(this).text();
});
}
});
console.log("Lets see the object...");
console.log(text);
I have added some console.logs to troubleshoot.
Here is a screenshot of the console.

So you see for some reason the request has failed.. any idea why?
english.xml simply contains:
<text id="call">Caller</text>
<text id="chat">Chatter</text>
Update:
Changed datatype to text and now getting success response but the ‘text’ object is not getting updated ?
var text = new Object();
$.ajax({
type: 'GET',
url: 'english.xml',
dataType: "text",
error: function(xhr, status, error) {
console.log(xhr);
console.log(xhr.responseText);
console.log(status);
console.log(error);
},
success: function(xml){
$(xml).find('text').each(function(){
text[$(this).attr('id')] = $(this).text();
});
console.log(xml);
console.log(text);
}
});
I would add
to the top of your document. I have a feeling since your telling it your return type will be xml it is expecting this and erroring when it doesnt find it.
Also shouldn’t your response type be
"application/xml"rather than just"xml"?Also you have async set to false, this means you are asking for a synchronous call. Just incase you were wondering
EDIT: I have edited since
application/xmlshould really be used instead oftext/xmlYou also need to have a root node
You can call your root node whatever you like, just try and make it something that makes sense.