AjaxOfGetAndPostTwo submission methods, GetIt mainly refers to the submission of a small amount of data.,Here I will talk about UsagePostProcess of sending large amounts of data.
Here I package all the content into oneXMLFile stream,Avoid sending long parameters,Load directly on the serverXMLAnalysis,Very convenient,No data loss..
Below is the process implementation idea:
Step 1:CreateXMLOfDomObject,Use the following method to complete
Function createdomdoc ()//CreateXMLDocument Object
{
VaR signatures = ["msxml2.domdocument. 5.0", "msxml2.domdocument. 4.0", "msxml2.domdocument. 3.0", "msxml2.domdocument", "Microsoft. xmldom"];
For (VAR I = 0; I <signatures. length; I ++)
{
Try
{
VaR domdoc = new activexobject (Signatures [I]);
Return domdoc;
}
Catch (E)
{
}
}
Return NULL;
}
Step 2:Get data from the client and write dataXM,The method is as follows::
Function createxml (DOC)
{
VaR root = Doc. createelement ("root ");
VaR Title = Doc. createelement ("title ");
Title. Text = Document. getelementbyid ("title"). value;
Root. appendchild (title );
VaR homepage = Doc. createelement ("Homepage ");
Homepage. Text = Document. getelementbyid ("Homepage"). value;
Root. appendchild (homepage );
Doc. appendchild (Root );
// Alert ("ddddd ");
Return Doc. xml;
}
Step 3 Mutual call
VaR domdoc = createdomdoc ();//Create object UseSendSend to server
If (domdoc! = NULL)
{
VaR xml = createxml (domdoc );//WriteXMLReturnXMLDocument
Alert (domdoc );//
}
Else
{
Alert ("Not InstalledMSXMLWidget");
}
Step 4AjaxSend
VaR XMLHTTP = createxmlhttp ();
XMLHTTP. onreadystatechange = function ()
{
If (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200)
{
Info = XMLHTTP. responsetext;
// Alert (Info );
}
Else
{
Alert ("AjaxCall failed!"+ XMLHTTP. status );
}
}
}
XMLHTTP. Open ("Post", "ajaxserver. aspx? Type = Add ", false );
XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ;");//Key,Otherwise, an error occurs.
XMLHTTP. Send (domdoc );//Sent must beDomdocDocument Object,If you send onlyXMLError"Statue = 500"
Server:
Set accept type,Prevent Chinese garbled characters
Request. contentencoding = system. Text.Encoding. Getencoding ("Gb2312");
Xmldocument xmldoc = new xmldocument ();//Create an XML Document Object
Xmldoc. Load (request. inputstream );//XML Document Object stream sent by Ajax // You can also accept common pipeline streams.
Xmlnode node = xmldoc. selectsinglenode ("// Title ");//Obtain the title Node
Title = node. innertext;//Get node Value
Partial explanation:
XMLHTTP. Open ("Post", "ajaxserver. aspx? Type = Add ", false );
OpenThe method must contain at least the preceding three parameters.,
Post/get:Sending type
Ajaxserver. aspx? Type = Add:Request page path
False:YesTrue,WhenTrueYes asynchronous request,Sending can continue to use the form, FalseLock form after sending,Until the result is returned..