I have a javascript which receives info from a servlet using jQuery:
$.get("authenticate", {badge:$('input#badge').val()}, function(data) {
console.log("xml: "+data);
displayInfoReturn(data);
});
When I process the result in Safari, everything works great:
function displayInfoReturn(data) {
if (/load/.test(data)) { // ...process string
}
}
But the ‘if’ always returns false in firefox (haven’t tried it yet in IE or Chrome). I also tried using indexOf != -1 and search != -1. Nothing works!
One curious thing I noticed however is when I print data to console:
console.log ("received... "+data);
it comes back with “received… [object XMLDocument]”. So apparently it’s not treating my data as a string. I tried data.toString() but that doesn’t work either. So how can I get firefox to play fair here?
What does your servlet return? An
application/xmldocument or justtext/plain? What have you set inresponse.setContentType()? You seem to be expecting XML and Firefox seems to be telling that it’s really an XML document, but yet you’re treating it as text/plain with that regex.test(). I’m not sure about Safari, but it look like that it has overridden atoString()on the XML document object so that it returns the whole XML string so that your regex by coincidence works fine.Without knowing the exact XML document it’s hard to tell how exactly to fix it. If it’s for example
Then you can check the presence of
loadvalue in the<action>tag using jQuery’s own XML parsing facilities as follows:See also: