开发者

JQuery- $(xmlObject).xml does not work in Mozilla but works in Internet Explorer

开发者 https://www.devze.com 2023-01-06 15:39 出处:网络
Consider the following snippet of code: function parseXml(xml) { xmlObject= xml; alert(xmlObject.xml); } function close(errroMsg)

Consider the following snippet of code:

function parseXml(xml)
{    
    xmlObject= xml;     
    alert(xmlObject.xml);
}
function close(errroMsg)
{
 //Displayed Error Message
}

$(document).ready(function()
{
  $.ajax(
            {
                type: "POST",              
   开发者_C百科             url: "ServiceProvider.aspx",
                dataType: "xml",
                success: parseXml,
                failure: close   
            }
       );
});

In IE-8 the alert(xmlObject.xml) disaplays xml string. but in Mozilla it displays undefined. I am using jquery-1.4.2 I was unable to figure out the error. Thanks in Advance.


IE has a slightly different implementation of XML documents from other browsers, one of the differences being that in IE there is an xml property of the document.

If you want to serialize the XML into a string in all browsers, you can use the following:

function serializeXmlDoc(xmlDoc) {
    if (window.XMLSerializer) {
        return (new window.XMLSerializer()).serializeToString(xmlDoc);
    } else if (typeof xmlDoc.xml != "undefined") {
        return xmlDoc.xml;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消