Home > Article > Web Front-end > The $.ajax() method transfers values between web pages
This article mainly introduces the specific implementation of the $.ajax() method to transfer values between web pages. Friends in need can refer to
ajaxtext1.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <script type="text/javascript" language="javascript" src="jquery.js"></script> <!-- 必须包含 jquery.js文件,否则将无法传值--> <head> <script type="text/javascript"> function fun(){ var ss; var radio1=document.getElementsByName("radio1"); //读取单选按钮的值 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, //也可以用注释的这方式来进行传值操作 data:{sendstr1:form1.text1.value,sendstr2:ss}, //也可以用 $("#text1").val()的方式读取text1中的元素值 success:function(data){ alert(data); } }); } </script> </head> <body> <p align="center"> <form id="form1" name="form1" action="" method="post" > 输入:<input type="text" name="text1" id="text1"><br> 金球:<input type="radio" name="radio1" value="梅西">梅西 <input type="radio" name="radio1" value="C罗">C罗<br> <input type="button" value="提交" onclick="fun()"> </form> </p> </body> </html>
ajaxtest2.jsp
<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%>
<h2 class="titName SG_txta" id="t_4f925fc30100la36">JQuery中$.ajax()方法参数详解 问百度或Google </h2>
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to download blob files with ajax using jQuery
AJAX simple pop-up layer effect implemented by jQuery
The native implementation of Ajax regarding the use of MIME types
The above is the detailed content of The $.ajax() method transfers values between web pages. For more information, please follow other related articles on the PHP Chinese website!