Submit a large amount of Ajax data in XML format

Source: Internet
Author: User

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..

Related Article

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.