1. Get a piece of text from the remote background
JavaScript code:
Function getdata (STR)
{
VaR ohttpreq = new activexobject ("msxml2.xmlhttp ");
Ohttpreq. Open ("Post", "notrefreshserver. aspx", false); // notrefreshserver. aspx is used to output data to the client.
Ohttpreq. Send ();
VaR result = ohttpreq. responsetext
Dialog. innerhtml = dialog. innerhtml + result; // dialog is a client control used to display data.
}
CS code:
String strputput = @ "PP: How are you? How are you? <Br> ";
Response. Buffer = true;
Response. Clear ();
Response. clearcontent ();
Response. clearheaders ();
Response. contenttype = "text/html ";
Response. charset = "UTF-8 ";
Response. Write (strputput );
Response. Flush ();
Response. Close ();
Put this code in the background page_load event of the notrefreshserver. ASPX page, then the result on the client will receive "PP said: Hello? How are you? <Br> "code.
2. Obtain the remote XML Dataset
The preceding Code retrieves a piece of text from the remote background. To obtain a remote XML dataset, use the following code:
Suppose there is an XML file with the following content:
<AA>
<A>
<B> B1 </B>
</A>
<A>
<B> b2 </B>
</A>
<A>
<B> B3 </B>
</A>
</AA>
JavaScript code:
Function getdata (STR)
{
VaR ohttpreq = new activexobject ("msxml2.xmlhttp ");
Ohttpreq. Open ("Post", "notrefreshserver. aspx", false); // notrefreshserver. aspx is used to output data to the client.
Ohttpreq. Send ();
VaR result = ohttpreq. responsetext;
VaR odoc = new activexobject ("msxml2.domdocument ");
Odoc. loadxml (result );
Items1 = odoc. selectnodes ("// AA/A/B ");
For (VAR I = 0; I <items1.length; I ++)
{
// Items1 [I]. Text to obtain the data such as "B1" and "B2", and process it here ..........
}
}
CS code:
String strpathfile = "XXX"; // relative path of the XML file
Xmldocument xmldoc = new xmldocument ();
Xmldoc. Load (strpathfile );
Xmltextwriter xtw = new xmltextwriter (response. outputstream, response. contentencoding );
Xmldoc. writeto (xtw); // if you want to obtain data from the database, use Ds. writexml (xtw); DS is the DataSet object.
Xtw. Formatting = formatting. indented;
Xtw. indentation = 4;
Xtw. indentchar = '';
Xtw. Flush ();
Response. End ();
Xtw. Close ();
Put this code in the background page_load event of the notrefreshserver. ASPX page. Then, the result of the client will receive the content of the XML file, and then display the data in the XML file.