I'm trying to port a portion of AJAX code I wrote over to the BlackBerry application's embedded browser. Our base build is 4.6.1 and the RIM documentation claims that开发者_C百科 XMLHttpRequest's responseXML is available starting with this version. And when I request an XML file from my local server, I get back the responseText (so I know the request is working), but the responseXML is always null. I've made sure the HTTP "Content-Type" header is set to "text/xml" and I am getting the correct data loaded in a web browser. It's just nulling out in the BB web environment. Does anyone know what might be happening?
A backup of using the responseText and piping it through DOMParser is not possible because that object was not added to the BB browser until 4.7.1. So I'm not sure what fallback I have.
Answering my own question... Hopefully I can save someone else a few hours of frustration.
Unfortunately, one of the files that I thought was returning with a content-type of text/xml was really coming back as text/html. I missed that. BB correctly does not try to parse something it thinks isn't xml. So on this point, I'm an idiot.
Several of my files were composed of empty, self-closing root-node tags (example below). I don't know for sure if this is valid or not, but all other browsers I've tested this code on worked fine. But on the BB, the XML stream below resulted in a null responseXML:
<?xml version="1.0" ?><rootnode />
I'd delete my question, but I think point number 2 should be a surprise to most developers I know.
精彩评论