Select menu example from the drop-down list for ajax to read database content

Source: Internet
Author: User

Copy codeThe Code is as follows:
<PRE class = javascript name = "code"> </PRE> <PRE class = javascript name = "code"> ------------------- This Is ajax (javascript) code --------------------------- </PRE> <PRE class = javascript name = "code"> </PRE> <PRE class = javascript name = "code"> function send_request (callback, urladdress, isReturnData ){
Var xmlhttp = getXMLHttpRequest ();
Xmlhttp. onreadystatechange = function (){
If (xmlhttp. readyState = 4) {// if readystate is 4, data transmission ends.
Try {
If (xmlhttp. status = 200 ){
If (isReturnData & isReturnData = true ){
Callback (xmlhttp. responseText );
}
} Else {
Callback ("sorry, this page is not found:" + urladdress + "");
}
} Catch (e ){
Callback ("sorry, failed to send the request, please try again" + e );
}
}
}
Xmlhttp. open ("POST", urladdress, true );
Xmlhttp. send (null );
}
Function getXMLHttpRequest (){
Var xmlhttp;
If (window. XMLHttpRequest ){
Try {
Xmlhttp = new XMLHttpRequest ();
Xmlhttp. overrideMimeType ("text/html; charset = UTF-8"); // sets the data to be identified by UTF-8 Encoding
} Catch (e ){}
} Else if (window. ActiveXObject ){
Try {
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){
Try {
Xmlhttp = new ActiveXObject ("Msxml2.XMLHttp ");
} Catch (e ){
Try {
Xmlhttp = new ActiveXObject ("Msxml3.XMLHttp ");
} Catch (e ){}
}
}
}
Return xmlhttp;
}
</PRE> ------------------------ this is the client form jsp code ---------------------------- <BR>
<% @ Page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% @ taglib uri ="/struts-tags "prefix =" s "%> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> Content = "text/html; charset = UTF-8"> <title> Insert title here </title> <script type = "text/javascript" src = "<% = request. getContextPath () %>/js/xmlhttp. js "> </script> <script type =" text/javascript "> function getProcess (value) {var process = document. getElementById ('process'); send_request (function (value2)
{Process. innerHTML = value2;}, "getProcessType. action? Value = "+ value, true );} </script> Value = "G"> Management process </option> <option value = "Z"> supported processes </option> </select> <div id = "process"> <select name = "smallclass"> <option value = "Level 1 process name" selected> select a level 1 process name </OPTION> </select> </div> <input type = "submit "value =" Submit "> </form> </div> </body> <PRE> </PRE>
<BR>
<P> <PRE class = html name = "code"> <PRE class = html name = "code"> ---------------------- this is the server action code ---------------------------- </PRE> <BR>
<P> </P>
<PRE> </PRE>
Here is my business logic, each logic is different, so this code is just to put the content to be displayed within the request range, and then return to the next page. javabean has my MyProcess class and its attributes.
<P> </P>
<P> <PRE class = java name = "code"> public String getProcessType (){
HttpServletRequest request = ServletActionContext. getRequest ();
String value = request. getParameter ("value ");
List <MyProcess> MyProcesses = processService. getprocpolicytype (value );
For (MyProcess p: MyProcesses ){
System. out. println (p. getName ());
}
Request. setAttribute ("list", MyProcesses );
Return SUCCESS;
} </PRE> <PRE class = html name = "code"> </PRE> <PRE class = html name = "code"> </PRE> <PRE class = html name = "code"> ------------------------ this is the Server jsp code ---------------------------- </PRE> <PRE class = html name = "code"> <% @ page language = "java" contentType = "text /html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<% @ Include file = "/page/share/taglib. jsp" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Insert title here </title>
</Head>
<Body>
<Select name = "smallclass">
<Option value = "Level 1 process name" selected> select a level 1 process name </OPTION>
<C: forEach items = "$ {list}" var = "myprocess">
<Option value = "$ {myprocess. processID}">
$ {Myprocess. name}
</Option>
</C: forEach>
</Select>
</Body>
</Html> </PRE> <BR>
<BR>
<P> </P>
<P> this process is almost the same! </P>
<P> <BR>
</P>
</PRE>

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.