An Ajax instance for paging

Source: Internet
Author: User

Now, more and more Ajax applications are used. The company found some materials on the Internet so that they can be used in the future, however, I have not found any examples in development. Now I have posted a simple example for your reference. I hope it will be helpful.

Program environment hibernate + spring + sturts

Code used for paging in JSP.

<Script language = "JavaScript">
VaR http_request = false;
Function send_request (URL) {// initialize, specify the processing function, and send the request Function
Http_request = false;
// Start initializing the XMLHTTPRequest object
If (window. XMLHttpRequest) {// Mozilla Browser
Http_request = new XMLHttpRequest ();
If (http_request.overridemimetype) {// sets the mime category
Http_request.overridemimetype ('text/xml ');
}
}
Else if (window. activexobject) {// IE browser
Try {
Http_request = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Http_request = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Http_request) {// exception. An error occurred while creating the object instance.
Window. Alert ("the XMLHTTPRequest object instance cannot be created .");
Return false;
}
Http_request.onreadystatechange = processrequest;
// Determine the request sending method and URL and whether to execute the following code synchronously
Http_request.open ("Post", URL, true );
Http_request.send (null );
}
// Function for processing the returned information
Function processrequest (){
If (http_request.readystate = 4) {// judge the object status
If (http_request.status = 200) {// The information has been returned successfully. Start to process the information.


Document. getelementbyid ('dd'). innerhtml = http_request.responsetext;
} Else {// The page is abnormal.
Alert ("the page you requested has an exception. ");
}
}
}
Function usercheck (username ){
Send_request ('<HTML: rewrite page = ""/>/ology/index. do? Bar = <Bean: write name = "barname"/> & ajx = 1 & page = '+ username );
}
</SCRIPT>

<TD id = "DD" width = "78%" Height = "493" valign = "TOP">
<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<TD width = "574"> & nbsp; </TD>
</Tr>
<Logic: notempty name = "bar" property = "content">
<Tr>
<TD> <Table width = "100%" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<TD Height = "4"> </TD>
</Tr>

<Logic: iterate id = "sub" name = "bar" property = "content">
<Tr>
<TD>
<Table width = "98%" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
& Lt; TD width = "16%" align = "center" & gt;
<Logic: equal name = "sub" property = "infopictype" value = "0">
<Bean: write name = "sub" property = "infominipic"/> "width =" 82 "Height =" 82 "border =" 0 ">
</Logic: equal>
<Logic: equal name = "sub" property = "infopictype" value = "1">

</Logic: equal>

</TD>
<TD width = "84%"> <SPAN class = "blue12px">
<Bean: write name = "sub" property = "infotitle"/> </span> <SPAN class = "f12dred"> [<a href =
<Logic: equal name = "sub" property = "isrelink" value = "0">
"<HTML: rewrite page =" "/>/ology/detail. do? Infoid = <Bean: write name = "sub" property = "infoid"/>"
</Logic: equal>
<Logic: equal name = "sub" property = "isrelink" value = "1">
"<Bean: write name =" sub "property =" relinkurl "/>"
</Logic: equal>
Target = "_ blank" class = "link_blue23_12"> full text </a>] </span> </TD>
</Tr>
</Table>
</TD>
</Tr>
<Tr>
<TD width = "10"> </TD>
</Tr>
<Tr>
<TD> & nbsp; </TD>
</Tr>
</Logic: iterate>
</Table> </TD>
</Tr>

<Tr>
<TD align = "center"> /appweb/ology/images/line001.gif "width =" 566 "Height =" 15 "> </TD>
</Tr>
<Tr>
<TD> <Div align = "center">
<SPAN class = "black12px"> pagination </span>
<A href = "javascript: usercheck ('1');" class = "link_blue23_12"> homepage </a> <SPAN class = "link_darkblue_12">
<A href = "javascript: usercheck ('<Bean: write name =" bar "property =" page. previouspage "/> ');" class = "link_blue23_12"> previous page </a> </span> <SPAN class = "link_blue23_12">
<A href = "javascript: usercheck ('<Bean: write name =" bar "property =" page. nextpage "/> ');" class = "link_blue23_12"> next page </a> </span> <SPAN class = "link_darkblue_12">
<A href = "javascript: usercheck ('<Bean: write name =" bar "property =" page. totalpage "/> ');" class = "link_blue23_12"> last page </a> </span>
<SPAN class = "black12px"> <Bean: write name = "bar" property = "page. currentpage "/>/<Bean: write name =" bar "property =" page. totalpage "/> page </span>
<SPAN class = "black12px"> 20 items/page </span> <SPAN class = "text_black_12px"> </div> </TD>
</Tr>
</Logic: notempty>
<Tr>
<TD> & nbsp; </TD>
</Tr>
</Table>
</TD>

Of course, this is not a complete JSP page. I just post the code of pagination.

In the paging link, we use js to call Ajax to send paging requests. I believe all users who have used sturts know that we have called action, and the return is a page, the reverse page will replace the above JSP page, which completes a simple Ajax request.

Of course this is just the most simple application, if you use different applications, welcome you to give me E-MAIL, we discuss together.

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.