我现在想问的是我现在用struts2 结合了jqeury用的是jqeury里的ajax事件$.ajax(
{
type: "POST",
url: "sturts2/example/Hello.action",
data:??????,
dataType:"html",
success:
function(msg) { }
在data那里传是知道 可是不知道怎么取那些页面里的值
我用ajax提交可是参数传不过去 我想把页面的全部的 input type=“text” 的值 在sturts java类里要取它。 我应该怎么传过去?
{
type: "POST",
url: "sturts2/example/Hello.action",
data:??????,
dataType:"html",
success:
function(msg) { }
在data那里传是知道 可是不知道怎么取那些页面里的值
我用ajax提交可是参数传不过去 我想把页面的全部的 input type=“text” 的值 在sturts java类里要取它。 我应该怎么传过去?
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script>
window.onload=function(){
var s = "";
$("input[type='text']").each(function(){s += $(this).attr("name")+":"+$(this).val()+",";})
if(s!='') s = s.substr(0,s.length-1);
s = "{" + s + "}";
alert(s);
}
</script><input type="text" name="x" value="xx">
<input type="text" name="y" value="yy">
<input type="text" name="x" value="zz">
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script>
window.onload=function(){
var s = "";
$("input[type='text']").each(function(){s += $(this).attr("id")+":'"+$(this).val()+"',";})
if(s!='') s = s.substr(0,s.length-1);
s = "{" + s + "}";
var dt;
eval("dt = " +s);
alert(dt.x)
}
</script><input type="text" id="x" value="xx">
<input type="text" id="y" value="yy">
<input type="text" id="x" value="zz">
var dt;
eval("dt = " +s);在这里为什么 必须得 eval("dt = " +s);啊? 为什么这么用就不行--》eval(s)
var decimal;
$.ajax({
async:false,
type:"Post",
url:"../findGoods.do?method=getDecimalByUnit&unitName="+unitName,
success:function(data){
decimal=data;
}
});
return decimal;
}atction public ActionForward getDecimalByUnit(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
String unitName=null;
try {
unitName=new String(request.getParameter("unitName").getBytes("ISO-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
WmsBaseUnitDAO dao=new WmsBaseUnitDAO();
String decimal=dao.getDecimalByUnit(unitName);
PrintWriter out=null;
try {
out=response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.print(decimal);
out.close();
return null;
}