Partial page refreshing using Ajax and IFRAME nesting

Source: Internet
Author: User

Use Ajax and IFRAME nesting to partially refresh the page. The javascript code is for reference only and needs to be modified as needed.
? 1. [Code] JavaScript code

Function cj_start (depname, groupid ){
VaR URLs = "<% = PATH %>/usergather. Action ";
VaR status = "";
VaR html_1 = "<IFRAME frameborder = \" 0 \ "scrolling = \" NO \ "width = \" 600 \ "Height = \" 60 \ "src = \" <% = basepath %> cj_status.jsp \ "style = \" margin-top: 3px; Vertical-align: middle; \ "> </iframe> ";
$ ("# Cj_status_html" ).html (html_1 );
VaR html_2 = "";
VaR cj_butoon = "";
$. Ajax ({
URL: URLs,
Type: "Post ",
Datatype: "JSON ",
Data: {depname: depname, groupid: groupid },
Success: function (data ){
If (data. cjstatus. length! = 0 ){
If (data. cjstatus [0] = "0 "){
Cj_button = "<input type = \" button \ "value = \" collection channel \ "Disabled = \" disabled \ "/> ";
$ ("# Cj_button_html" ).html (cj_button );
}
For (VAR I = 1; I <data. cjstatus. length; I ++ ){
Html_2 + = data. cjstatus [I] + "";
}
$ ("# Cj_status_html" ).html (html_2 );
} Else {
Html_2 = "Collection System error. Please contact the developer! ";
$ ("# Cj_status_html" ).html (html_2 );
}
}
});
}
2. [Code] part of JSP code

<Tr>
<TD id = "cj_button_html">
<Input type = "button" name = "caiji" value = "collection channel" onclick = "cj_start ('<% = depname %> ', '<% = groupid %>'); "/>
</TD>
</Tr>
<Tr>
<TD id = "cj_status_html">

</TD>
</Tr>
3. [Code] cj_status.jsp code
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<% Http://www.bizhizu.cn/manhua?
String Path = request. getcontextpath (); cartoon image
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>
 
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">
</Head>

<Body>
<Div>
images/loading_16x16.gif"/> <span> collecting data. Please wait... </span>
</Div>
 
<Script language = "JavaScript">
Function myrefresh ()
{
Window. Location. Reload ();
}
SetTimeout ('myrefresh () ', 1000); // refresh once per second
</SCRIPT>
</Body>
</Html>
?

Partial page refreshing using Ajax and IFRAME nesting

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.