首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

javascript怎么向action传参数

2012-01-30 
javascript如何向action传参数javascript中如何向action传参数,所有代码必须都写在javascript中,不能写在j

javascript如何向action传参数
javascript中如何向action传参数,所有代码必须都写在javascript中,不能写在jsp页面上面。

例如:function aben(x,y){
alert(x);
}
这个里面string型的x,y如何传到action中,要求代码就在javascript中写,麻烦action端怎么接受的代码也写出来,不胜感激。本人在线等,对了立刻结贴!

[解决办法]
<script>
function sub(x,y){
var url = "xxx.do?x="+x+"&amps;y="+y;
document.location.href = url;
}
</script>

<input type="button" href="#" onclick="sub(x,y);"/>

action端
request.getParameter("x")
request.getParameter("y")
[解决办法]
1楼方法可行。
JS中也可以修改form中input控件的value值,然后提交form。
[解决办法]
可以使用AJAX来完成,呵呵

function userFeedback(x,y){
alert(x);
$.ajax( {
url : '../userfeedback.html',
type : 'POST',
data : {
input: x,
input2: y
},
dataType : "text",
success : function() {

},
error : function() {
alert("Error loading json document");
}
});
alert(y);
}

热点排行