如何“点击链接”传递参数到另一页面并执行AJAX
如<ahref="abc.asp?search=123">点击链接</a>而abc.asp里有<inputtype="text"name="凭证编号"id="凭证编号"o...
如<a href="abc.asp?search=123">点击链接</a>
而abc.asp里有
<input type="text" name="凭证编号" id="凭证编号" onchange="autosearch()"/>
autosearch()是接收search参数并执行ajax 展开
而abc.asp里有
<input type="text" name="凭证编号" id="凭证编号" onchange="autosearch()"/>
autosearch()是接收search参数并执行ajax 展开
2个回答
展开全部
<script>
var xmlHttp;
function autosearch(){
var locationUrlName = window.location.search;
var searchContent = "";
if(locationUrlName.indexOf("search=")!=-1){
searchContent = locationUrlName.split("search=")[1];//接受传过来的参数
}
startRequest('ajax请求的url');
}
function getParam(){
return new Date().getTime();
}
function createXMLHttpRequest() {
xmlHttp = false;
if(window.XMLHttpRequest) { //Mozilla
xmlHttp = new XMLHttpRequest();
if (xmlHttp.overrideMimeType) {
xmlHttp.overrideMimeType("text/xml");
}
}else if (window.ActiveXObject) { // IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xmlHttp) {
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
}
function processRequest() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
try{
doWhenAjaxRequestIsOk(xmlHttp.responseText);
}catch(e)
{
alert(e+"无法调用doWhenAjaxRequestIsOk方法");
}
} else {
//alert('xmlHttp.status:'+xmlHttp.status);
//alert("您所请求的页面有异常");
}
}
}
function startRequest(strurl){
createXMLHttpRequest();
xmlHttp.onreadystatechange = processRequest;
xmlHttp.open("Get", strurl+"?"+getParam(), true);
xmlHttp.send(null);
}
function doWhenAjaxRequestIsOk(requestText){
//回调函数
}
</script>
var xmlHttp;
function autosearch(){
var locationUrlName = window.location.search;
var searchContent = "";
if(locationUrlName.indexOf("search=")!=-1){
searchContent = locationUrlName.split("search=")[1];//接受传过来的参数
}
startRequest('ajax请求的url');
}
function getParam(){
return new Date().getTime();
}
function createXMLHttpRequest() {
xmlHttp = false;
if(window.XMLHttpRequest) { //Mozilla
xmlHttp = new XMLHttpRequest();
if (xmlHttp.overrideMimeType) {
xmlHttp.overrideMimeType("text/xml");
}
}else if (window.ActiveXObject) { // IE
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xmlHttp) {
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
}
function processRequest() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
try{
doWhenAjaxRequestIsOk(xmlHttp.responseText);
}catch(e)
{
alert(e+"无法调用doWhenAjaxRequestIsOk方法");
}
} else {
//alert('xmlHttp.status:'+xmlHttp.status);
//alert("您所请求的页面有异常");
}
}
}
function startRequest(strurl){
createXMLHttpRequest();
xmlHttp.onreadystatechange = processRequest;
xmlHttp.open("Get", strurl+"?"+getParam(), true);
xmlHttp.send(null);
}
function doWhenAjaxRequestIsOk(requestText){
//回调函数
}
</script>
展开全部
我自己搜索出来了,记录一下,也给以后的兄弟一个例子.
=================================
1.asp如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>主页面</title>
</head>
<body>
<form name="frm" method="post" action="3.asp">
<table>
<tr><td>
<input type=text name="shop">
<a href=2.asp target=_blank>选择客户</a>
</td></tr>
<tr><td>
<input type="submit" name="Submit" value="添加记录">
</td></tr>
</table>
</form>
</body>
</html>
-----------------------
2.asp如下
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>被调用页</title>
<script language=javascript>
function td_click(str){
window.opener.document.frm.shop.value=str
window.close()
}
</script>
</head>
<body>
<form>
<table>
<tr><td onclick="td_click('11')">11</td></tr>
<tr><td onclick="td_click('222')">222</td></tr>
<tr><td onclick="td_click('333')">333</td></tr>
<tr><td onclick="td_click('444')">444</td></tr>
</table>
</form>
</body>
</html>
----------------------
3.asp如下
<%
shop=request("shop")
%>
<%=shop%>
===================================
一觉睡起来再搜索,很爽.
=================================
1.asp如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>主页面</title>
</head>
<body>
<form name="frm" method="post" action="3.asp">
<table>
<tr><td>
<input type=text name="shop">
<a href=2.asp target=_blank>选择客户</a>
</td></tr>
<tr><td>
<input type="submit" name="Submit" value="添加记录">
</td></tr>
</table>
</form>
</body>
</html>
-----------------------
2.asp如下
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>被调用页</title>
<script language=javascript>
function td_click(str){
window.opener.document.frm.shop.value=str
window.close()
}
</script>
</head>
<body>
<form>
<table>
<tr><td onclick="td_click('11')">11</td></tr>
<tr><td onclick="td_click('222')">222</td></tr>
<tr><td onclick="td_click('333')">333</td></tr>
<tr><td onclick="td_click('444')">444</td></tr>
</table>
</form>
</body>
</html>
----------------------
3.asp如下
<%
shop=request("shop")
%>
<%=shop%>
===================================
一觉睡起来再搜索,很爽.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询