AJAX and the Mozilla XMLHttpRequest object

September 26, 2005 – 8:19 pm

I am just learning the full in’s and out’s of the javascript DOM and XMLHttpRequest object model for Mozilla. I wanted to be able to duplicate the results the XMLHttpRequest Object returns. I thought I just wanted XML, however it turns out the request object automatically places the xml returned into the DOM parser and returns that object. There may be a way to turn this off, I’m not sure yet, however here is the code to simulate the DOM parsing of a javascript string:

var xmlString = '<passwd>' + 
'  <user id="101">' +
'    <login>mark</login>' + 
'    <group id="100"/>' +
'  </user>' +
'</passwd>'
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlString, "application/xml");

It should be noted that the javascript var uses “+”’s to avoid a very long xml line (since newlines will break the syntax).

I found this as a good quick reference to the parsing and serializing of XML data. Apple also has a nice tutorial available on their website.

You must be logged in to post a comment.