Ajaxtext1.jsp
Copy codeThe Code is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<Script type = "text/javascript" language = "javascript" src = "jquery. js"> </script> <! -- The jquery. js file must be included; otherwise, the value cannot be passed. -->
<Head>
<Script type = "text/javascript">
Function fun (){
Var ss;
Var radio1 = document. getElementsByName ("radio1"); // read the value of the radio button
For (var I = 0; I <radio1.length; I ++ ){
If (radio1.item (I). checked ){
Ss = radio1.item (I). value;
Break;
}
}
// Var sendstr = "sendstr1 =" + form1.text1. value + "& sendstr2 =" + ss;
$. Ajax ({
Type: "POST ",
Url: "ajaxtest2.jsp ",
Async: false,
// Data: sendstr, // You can also use the annotation method to upload values.
Data: {sendstr1: form1.text1. value, sendstr2: ss}, // you can also use $ ("# text1"). val () to read the element values in text1.
Success: function (data ){
Alert (data );
}
});
}
</Script>
</Head>
<Body>
<Div align = "center">
<Form id = "form1" name = "form1" action = "" method = "post">
Input: <input type = "text" name = "text1" id = "text1"> <br>
Ballon: <input type = "radio" name = "radio1" value = "Messi"> Messi
<Input type = "radio" name = "radio1" value = "Cristiano Ronaldo"> Cristiano Ronaldo <br>
<Input type = "button" value = "Submit" onclick = "fun ()">
</Form>
</Div>
</Body>
</Html>
Ajaxtest2.jsp
Copy codeThe Code is as follows:
<Pre code_snippet_id = "269881" snippet_file_name = "blog_20140402_4_8173458" class = "javascript" name = "code"> <% @ page contentType = "text/html; charset = UTF-8" %>
<%
Request. setCharacterEncoding ("UTF-8 ");
String sendstr1 = request. getParameter ("sendstr1 ");
String sendstr2 = request. getParameter ("sendstr2 ");
String sReturn = sendstr1 + "_ new _" + sendstr2;
%>
<% = SReturn %> </pre> <pre code_snippet_id = "269881" snippet_file_name = "blog_20140402_5_3124712" class = "javascript" name = "code"> </pre> <pre code_snippet_id = "269881" snippet_file_name = "blog_20140402_5_3124712" class = "javascript" name = "code">
</H2> </pre>
<Pre> </pre>
<Div style = "top: 177px"> adjust margin </div>
<Pre> </pre>