Passing XML through jquery-Ajax

Source: Internet
Author: User
Program Code

$. Ajax ({
URL: ' Accept. jsp ' ,
Type: ' Post ' , // Data Transmission Method
Datatype: ' XML ' , // Note that here is XML, not HTML (HTML is relatively simple, so I will use XML as an example to explain it)
Data: ' TEXT = ' + $ ( " # Name " ). Val () + ' & Amp; Date = ' + New Date (), // Data to be transferred
Timeout: 2000 , // Set local timeout. (MS)
Error: Function (){
Alert ( ' Error loading XML document ' );
},
Success: Function (XML ){
$ (XML). Find ( " Student " ). Each ( Function (){
VaR Item_text = $ ( This ). Text ();
// Alert ($ ("name", XML). Text (); // note the syntax of the selector.
$ ( ' <Li> </LI> ' Pai.html (item_text). appendto ( ' Ol ' );
});
}
});

Body:
Program code

< Form ID = "Form1" >
Name: < Input Type = "Text" Value = "Cssrain" ID = "Name" > < BR >
< Input Type = "Button" Value = "Save" ID = "Save" >
</ Form >
< BR >
Returned XML:
< Ol > </ Ol >

Accept. jsp: String text = Request. getparameter ( " Name " ); // Obtain incoming Parameters
Response. setcontenttype ( " Text/XML " ); // Note: Because you passed it in XML format, it must be written here.
Out. Print ( " <? XML version = \ " 1.0 \ " Encoding = \ " UTF - 8 \ " ?> " );
Out. Print ( " <Student> " );
Out. Print ( " <Name> " + Text + " </Name> " );
Out. Print ( " </Student> " );

Well, the example is here, so I should be able to understand it. Now the XML is returned. But I heard that JSON is full of popularity. I will be doing some JSON transfer examples later.

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.