Home >Web Front-end >JS Tutorial >The $.ajax() method transfers values ​​between web pages

The $.ajax() method transfers values ​​between web pages

不言
不言Original
2018-07-02 17:16:422518browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn