AJAX large Data XML format submission

Source: Internet
Author: User

Ajax get and Post's two submission methods, get is mainly a small amount of data submission, here I talk about the process of sending a lot of data by post method.

Here I package all the content as an XML file stream, avoid the long parameter send, on the server side directly load XML parsing, very convenient, the data also did not lose phenomenon.

The following is the implementation of the process of thinking:

Step One: Create an XML DOM object that you can use to do the following

function Createdomdoc ()//Creating an XML Document 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 two: Get data from the client to be written to XM 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;

}

The third step calls each other

var domdoc = Createdomdoc (); The creation object will be sent to the server side with send

if (domdoc!=null)

{

var xml = Createxml (Domdoc); Write XML return XML document

alert (domdoc);//

}

Else

{

Alert ("No MSXML controls are installed");

}

Fourth Step Ajax Send

var xmlhttp=createxmlhttp ();

Xmlhttp.onreadystatechange = function ()

{

if (xmlhttp.readystate = 4)

{

if (Xmlhttp.status = 200)

{

Info =xmlhttp.responsetext;

alert (info);

}

Else

{

Alert ("The AJAX call failed.") "+xmlhttp.status);

}

}

}

Xmlhttp.open ("POST", "Ajaxserver.aspx?type=add", false);

Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded;"); Critical, otherwise error

Xmlhttp.send (Domdoc); Send must be a Domdoc document object, if only send XML will make an error "statue=500"

Server-Side :

Set accept type to prevent garbled situation in Chinese

request.contentencoding = System.Text.Encoding.GetEncoding ("gb2312");

XmlDocument xmldoc = new XmlDocument (); Building an XML Document object

XmlDoc. Load (Request.inputstream); Accept AJAX-sent XML Document object stream//can also accept normal character streams

XmlNode node = xmldoc.  selectSingleNode ("//title"); Get title Node

title = node. InnerText; Get node value

partly explained:

Xmlhttp.open ("POST", "Ajaxserver.aspx?type=add", false);

The Open method contains at least three of the above parameters.

Post/get: Send Type

Ajaxserver.aspx?type=add: Request page Path

False: Can be true, when True is the request asynchronous, send can continue to use the form, false when sent lock the form, until the result 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.