How to load json data using xml dom on the client

Source: Internet
Author: User

Steps:
1. Reference Jquery
2. for IE, the instance ActiveXObject; Firefox, And the instance DOMParser.
3. Processing Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Default. aspx. cs" Inherits = "XmlDom. _ Default" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>

<Script type = "text/javascript" src = "js/jquery-1.4.2.js"> </script>

<Script type = "text/javascript">
// Get the XML Dom
Function LoadXML (XmlString ){
Var xmlDoc;
// Firefox, etc.
If (! Window. ActiveXObject ){
Var parser = new DOMParser ();
XmlDoc = parser. parseFromString (XmlString, "text/xml ");
} Else {
// IE
XmlDoc = new ActiveXObject ("Microsoft. XMLDOM ");
XmlDoc. async = "false ";
XmlDoc. loadXML (XmlString );
}
Return xmlDoc;
}
Function UseCllentXmlDom (){
Try {
Var string = "<Log> <Content value = 'test Xml Dom use'/> </Log> ";
// Load
Var xmlString = LoadXML (string );
Var xmlContent = $ (xmlString). find ("Content ");
If (xmlContent! = Null ){
$ (XmlString). find ("Content"). each (function (){
Var ContentValue = $ (this). attr ("value ");
// Display the obtained data
$ ("# DomValue" pai.html (ContentValue );
});
}
}
Catch (e ){
Throw e;
}
}
</Script>

</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<A style = "cursor: pointer" onclick = "UseCllentXmlDom ()"> call the client XmlDom </a>
<Br/>
Show data:
<Div id = "DomValue">
</Div>
</Div>
</Form>
</Body>
</Html>

In FireFox, I found that Jquery can directly process XML strings directly to Jquery, but not IE. The following code is used.Copy codeThe Code is as follows: <script type = "text/javascript">
// Applicable only in firefox
Function UseCllentXmlDom (){
Try {
Var string = "<Log> <Content value = 'test Xml Dom use'/> </Log> ";
// Retrieve the XML string
XmlString = $ (string );
Var xmlContent = $ (xmlString). find ("Content ");
If (xmlContent! = Null ){
$ (XmlString). find ("Content"). each (function (){
Var ContentValue = $ (this). attr ("value ");
// Display the obtained data
$ ("# DomValue" pai.html (ContentValue );
});
}

}
Catch (e ){
Throw e;
}
}
</Script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.