87,909
社区成员
发帖
与我相关
我的任务
分享
<title>aaaa页面往bbbb页面通过jquery的AJAX传递参数</title>
<script src="http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function() {
$('.div11 a').click(function() {
//先获取包含有汉字的href=newurl
var newurl = $(this).attr("href",$(this).attr("href") + "&hanzi=" + $(this).text());
alert(newurl.attr('href'));
//然后通过ajax把参数传递给bbbb.asp,相当于bbbb.asp?act=find&name=333&age=25&hanzi=可获取汉字的超链接
$.ajax({
url: 'bbbb.asp',
type: 'POST',
data: newurl.attr('href'),//这部分要怎么写呢?success和error是下面这种吗?
success: function (data) { alert('成功:'+data)},
error: function (xhr) { alert('服务器出错,返回内容:'+xhr.responseText)}
});
return true;
});
});
</script>
<div class="div11">
<li><a href="aaaa.asp?act=find&name=333&age=25">可获取汉字的超链接1111111</a></li>
<li><a href="aaaa.asp?act=find&name=444&age=60">可获取汉字的超链接2222222</a></li>
<li><a href="aaaa.asp?act=find&name=666&age=40">可获取汉字的超链接3333333</a></li>
</div>
$(function () {
$('.div11 a').click(function () {
//先获取包含有汉字的href=newurl
var newurl = $(this).attr("href") + "&hanzi=" +encodeURIComponent( $(this).text());//注意编码
newurl = newurl.replace('aaaa.asp', 'bbbb.asp')///替换下页面就行了,注意bbbb.asp中用request或request.querystring获取参数,因为是参数get提交
alert(newurl)
$.ajax({
url: newurl,//////////////////////////
type: 'POST',
data: {},//
success: function (data) { alert('成功:' + data) },
error: function (xhr) { alert('服务器出错,返回内容:' + xhr.responseText) }
});
return false;//阻止默认连接跳转
});
});
<title>aaaa页面往bbbb页面通过jquery的AJAX传递参数</title>
<base target="_blank" /> <!-- 确保超链接都是在新窗口打开 -->
<script src="http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function () {
$('.div11 a').click(function () {
//先获取包含有汉字的href=newurl
var newurl = $(this).attr("href") + "&hanzi=" +encodeURIComponent( $(this).text());//注意编码
//////这里要先跳转到cccc.asp?act=find&name=333&age=25&hanzi=可获取汉字的超链接11111(也要带这些汉字)
/////然后再开始构建向bbbb.asp传递参数的ajax
newurl = newurl.replace('cccc.asp', 'bbbb.asp')///替换下页面就行了,注意bbbb.asp中用request或request.querystring获取参数,因为是参数get提交
alert(newurl)
$.ajax({
url: newurl,//////////////////////////
type: 'POST',
data: {},//
success: function (data) { alert('成功:' + data) },
error: function (xhr) { alert('服务器出错,返回内容:' + xhr.responseText) }
});
return false;//阻止默认连接跳转
});
});
</script>
<div class="div11">
<li><a href="cccc.asp?act=find&name=333&age=25">可获取汉字的超链接1111111</a></li>
<li><a href="cccc.asp?act=find&name=444&age=60">可获取汉字的超链接2222222</a></li>
<li><a href="cccc.asp?act=find&name=666&age=40">可获取汉字的超链接3333333</a></li>
</div>
最终既要新开窗口到cccc.asp?act=find&name=333&age=25&hanzi=可获取汉字的超链接11111
bbb.asp的参数传递也要成功。
谢谢老大!!!