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.