I know we love JSON (I do too), but sometimes, it's easier to store the
data on the server without any json wrappers. In this case, we're not
saving XML fragments either. We want to replace a part of the page's
content specifically with a page that is content in its own right, so
it has HTML,DOCTYPE, etc. on top.
/*
Use this in contexts like:
def = doSimpleXMLHttpRequest('myfile.xhtml');
def.addCallback(swapFromHttp, 'myId');
where $('myId') is the DOM that you want replaced with content
with the same id="myId" DOM element in the xml request
caveats:
IE 6 needs the Content-type: text/xml
Firefox wants
IE and Safari don't handle named entities like well in this
context
and should be numeric (e.g.  )
*/
function swapFromHttp(myId, xmlhttp) {
var resXML=xmlhttp.responseXML;
var curr=$(myId);
var scrollPos=curr.scrollTop; //save scroll position
var newDOM = null;
try {
if (typeof(resXML.getElementById) == 'undefined') {
//IE HACK
//IE doesn't work because XML DOM isn't as rich as HTML DOM
var findID = function(node) {
if (newDOM) {return null;} //don't waste time after we've found
it
if (node.nodeType != 1) {
//document node gets us going
return (node.nodeType == 9) ? node.childNodes : null;
}
if (node.getAttribute('id') == myId) {
newDOM = node;
return null;
}
return node.childNodes;
};
nodeWalk(resXML, findID); //walk the html tag
curr.outerHTML=newDOM.xml;
}
else {
newDOM=resXML.getElementById(myId);
if (newDOM.outerHTML) {
//SAFARI HACK
//SAFARI fails because XML dom node can't be added into a
replaceChild HTML function
curr.innerHTML=newDOM.innerHTML;
}
else {
//probably Firefox
swapDOM(curr,newDOM);
}
}
$(myId).scrollTop = scrollPos;
} catch(err) {
//we might be catching an XML parsing error
logError(err);
logError(err.message);
if (resXML.parseError) {
logDebug('xml error:', resXML.parseError.errorCode);
logDebug(resXML.parseError.reason);
logDebug(resXML.parseError.line);
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---