近来用ajaxAnywhere.getAJAX(url),发现了一个小问题,就是第一次触发时,不会刷新相应的区域;尝试了好几次,发现ajaxAnywhere.getAJAX(url, zonesToRefres)这个API,把对应的zone设置为第二个参数,就能如愿以偿了。
本人用到的代码参考如下,给初学者一个参考:
这部分代码实现的功能很简单,就是弹出一个div窗口,显示相关内容。
css部分:
<style>
.white_content {
display: none;
position: absolute;
top: 35%;
left: 30%;
width: 120%;
height: 40%;
padding: 5px;
border: 5px solid orange;
background-color: white;
z-index:1002;
overflow: auto;
}
</style>
js部分:
<script>
function showRates() {
var num = document.getElementById('numperroom').value;
var housetype = document.getElementById('order.housetype').value;
var rateCode = document.getElementById('ratecode').value;
var startDate = document.getElementById('sdate').value;
var endDate = document.getElementById('edate').value;
ajaxAnywhere.getAJAX('<s:url action="toSelectRate"/>?num='+num + '&housetype=' + housetype + '&rateCode=' + rateCode + '&startDate=' + startDate + '&endDate=' + endDate, 'rateListzone');
ajaxAnywhere.getZonesToReload = function () {
return 'rateListzone';
};
ajaxAnywhere.onAfterResponseProcessing=afterGetRatesResponse;
}
function afterGetRatesResponse() {
document.getElementById('light').style.display='block';
}
</script>
页面部分代码:
<s:a href="#" οnclick= "showRates();"><font color="red">当前租金:</font></s:a>
<aa:zone name="rateListzone">
<div id="light" class="white_content">
<table width="100%">
<tr align="right">
<td align="left"><font color="red">显示在住期间租金</font></td>
<td align="right">
<img src="images/close_1.jpg" alt="关闭窗口" align="right" width="17" height="17" style="cursor:hand;" onClick="document.getElementById('light').style.display='none';">
</td>
</tr>
</table>
<table bgcolor="#B1D2FB">
<tr>
<td>星期日</td>
<td>星期一</td>
<td>星期二</td>
<td>星期三</td>
<td>星期四</td>
<td>星期五</td>
<td>星期六</td>
</tr>
<s:iterator value="ratePerWeekList">
<tr>
<td bgcolor="#FFFFFF"><s:property value="Sun"/></td>
<td bgcolor="#FFFFFF"><s:property value="Mon"/></td>
<td bgcolor="#FFFFFF"><s:property value="Tue"/></td>
<td bgcolor="#FFFFFF"><s:property value="Wed"/></td>
<td bgcolor="#FFFFFF"><s:property value="Thu"/></td>
<td bgcolor="#FFFFFF"><s:property value="Fri"/></td>
<td bgcolor="#FFFFFF"><s:property value="Sat"/></td>
</tr>
</s:iterator>
</table>
</div>
</aa:zone>