JQUERY 应用AJAX返回字符串

[color=red]//jquery --AJAX返回字符串————jsp/js部分[/color]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" CONTENT="no-cache">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Expires" CONTENT="-1">
<script type="text/javascript" src="${path}/js/jquery-1.4.2.min.js"></script>
<script language="javascript">
[color=red]//jquery --AJAX返回字符串[/color]
$(function() {
$("#selectName").change(function(){
var selectName = $("selectName").val();
$.post("${path}xxx.do",
{ selectName:selectName},
function(data){
var arr =data.split(",");
var A1=arr[0];
var A2=arr[1];
var A3=arr[2];
document.getElementById("msg").innerHTML="<font color='red'>"+A1+"</font>";
document.getElementById("a2name").value=A2;
document.getElementById("a3name").value=A3;
}
)

});

});
</script>
</head>
<body>
<form action="" name="frm" id="frm">
<table width="270" border="0" align="center" cellpadding="0" cellspacing="5" class="viewtext">
<tr align="left" valign="top">
<td align="right" width="200">下拉列表框的chang事件 jquery --AJAX</td>
<td width="49" align="left">
<select name="selectName" id="selectName" />
<option value="">--请选择--</option>
<option value="1">AA</option>
<option value="2">BB</option>
<option value="3">CC</option>
<option value="4">DD</option>
</select>
</td>
<td id="msg"></td>
<td>
<input type="text" name="a2name" id="a2name" />
<input type="text" name="a3name" id="a3name" />
</td>
</tr>
</table>
</form>
</body>
</html>

[color=red]//struts2 Action部分[/color]

public String getAjaxResult(){
request = ServletActionContext.getRequest();
response=ServletActionContext.getResponse();
String selectName=request.getParameter("selectName");

//业务根据参数selectName得到想要的一个或多个字符串
//如果是一个直接返回,如果是多个可以拼接成一个字符串
//返回结果值代码省略 ,在这只返回三个字符串

try {
String resultString = A1+","+A2+","+A3;
ServletActionContext.getResponse().getWriter().print(resultString);

} catch (IOException e) {
e.printStackTrace();
}
return null;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值