$. Ajax ()

Source: Internet
Author: User

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>

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.