Jquery Ajax application

Source: Internet
Author: User

-------------------------- Index. jsp --------------------------

<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"
Http://www.w3.org/TR/html4/loose.dtd>
<HTML>
<Head>
<Title> Ajax request data </title>
<SCRIPT type = "text/JavaScript" src = "jquery-1.3.2.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript"> <! --
// Datatype: "script", "html", "XML", "JSON"
Jquery. Ajax ({
Type: "Post ",
URL: "myjsp. jsp ",
Data: "id = 1 ",
Datatype: "script ",
Success: function (){
Jquery. Each (APRs. Result, function (I, data ){
Jquery ("# message"). append (data. sencond + "<br> ");
});
},
Complete: function (){
Jquery ("# message"). append ("request completed ");
},
Error: function (){
Jquery ("# message"). append ("request error ");
}
});
/* Jquery. getscript ("myjsp. jsp? Id = 1 ", function (){
Jquery. Each (APRs. Result, function (I, AA ){
Jquery ("# message"). append (AA. sencond + "<br> ");
});
});
Jquery. getjson ("myjsp. jsp", {ID: 2}, function (data ){
Jquery. Each (data. Result, function (I, AA ){
Jquery ("# message"). append (AA. sencond + "<br> ");
});
});
Jquery. Post ("myjsp. jsp", {ID: 3}, function (data ){
Jquery ("# message"). append (data );
});*/

--> </SCRIPT>
</Head>
<Body>
<Div id = "Images"> </div>
Request data output:
<Br/>
<Br/>
<Div id = "message"> </div>
</Body>
</Html>
--------------------------------- Myjsp. jsp ---------------------------------

<% @ Page contenttype = "application/X-JavaScript" Language = "Java" pageencoding = "UTF-8" %>
<% IF (request. getparameter ("ID"). Equals ("1") {%>
VaR APRs = {
Keyword: 'name ',
Result:
[
{Num: '1', sencond: 'test getscript1 '},
{Num: '2', sencond: 'test getscript2 '}
]
}
<%} Else if (request. getparameter ("ID"). Equals ("2") {%>
{
Keyword: 'name ',
Result:
[
{Num: '1', sencond: 'test getjson1 '},
{Num: '2', sencond: 'test getjson2 '}
]
}
<%} Else if (request. getparameter ("ID"). Equals ("3") {%>
Simple result
<% }%>

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.