reading out an xml (working) and returning the value as a string (not working yet)
For a site I'm working on I have a function that reads out an xml and needs to respond if an item starts with "MUZ ".
Currently I have this snippet of code:
- function itemCode() {
- $.ajax({
- type: "GET",
- url: "http://ican'tsharethisurl.so/sorry.xml",
- dataType: "xml",
- success: function(xml) {
- // I create a variable that holds the (unique) id
- var itemcode = $(xml).find('Current itemCode'); // I create a variable holding the id
- // If this id starts with "MUZ " then I need to execute some function with the id
- // sometimes people forget to use capitals, no biggie
- if (itemcode.toString().substring(0,3).toLowerCase() == "muz ") {
- // we'll just feed back the itemcode untill I get this up and running
- $("#data").html(itemcode);
- } else {
- $("#data").html(itemcode+" is not 'MUZ '");
- }
- }
- });
- }
The problem is that it doesn't convert to a string so it always ends up als a false statement.
Now the funny part is that if I use $("#data").html(itemcode) I get 'MUZ 4528'.
If I use $("#data").html(itemcode+" is not 'MUZ '") I get '[object Object] is not 'MUZ '.
I read out the object using an iteration but I couldn't figure it out...
Can anybody help me?
part of the xml:
- <broadcastmonitor>
- <useless elements></useless elements>
- <current>
- <useless elements></useless elements>
- <itemcode>MUZ 4528</itemcode>
- <useless elements></useless elements>
- </current>
- <useless elements></useless elements>
- </broadcastmonitor>
Any ideas ?