如何在不创建单独的jsp的情况下刷新表
How to refresh a table without creating a separate jsp?
我有一个表和一个搜索字段,根据搜索字段中输入的内容刷新表的内容,如果搜索字段中没有输入任何内容,则加载整个表。在这里,当用户单击Go按钮时,就会进行ajax调用。
目前,我有两个jsp如下:
主JSP
<script type="text/javascript">
$(document).ready(function() {
$( "#go-user" ).click(function() {
var userId = $('#usrId').val();
alert(userId);
$.ajax({
url: 'popUserSelect', // action to be perform
type: 'POST', //type of posting the data
data: { userId: userId }, // data to set to Action Class
dataType: 'html',
success: function (html) {
alert(html);
$('#load-user').html(html);
//document.getElementById("leftDiv").innerHTML=html; //set result.jsp output to leftDiv
},
error: function(xhr, ajaxOptions, thrownError){
alert('An error occurred! ' + thrownError);
}
});
return false;
});
});
</script>
<s:form theme="simple">
User Id : <s:textfield name="userId" id="usrId" theme="simple"/>
<s:submit action="popUserSelect" key="Go"></s:submit>
</s:form>
<div id="load-user">
<table width="100%">
<thead>
<tr>
<th>Select</th>
<th>ID</th>
<th>Name</th>
<th>Role</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<s:iterator value="userSupList" >
<tr>
<td><input type="radio" class="RadioButton" name="userRadio" value='<s:property value="USR_AMLUSERNAME"/>' /></td>
<td><s:property value="USR_AMLUSRID"/></td>
<td><s:property value="USR_AMLUSERNAME"/></td>
<td><s:property value="USR_ROLEID"/></td>
<td><s:property value="USR_LOCATIONID"/></td>
</tr>
</s:iterator>
</tbody>
</table>
</div>
<input type="button" value="Submit" onclick="buttonClick('SubmitUser')"/>
<input type="button" value="Cancel" onclick="buttonClick('Close')"/>
刷新Jsp:
<table width="100%">
<thead>
<tr>
<th>Select</th>
<th>ID</th>
<th>Name</th>
<th>Role</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<s:iterator value="userSupList" >
<tr>
<td><input type="radio" class="RadioButton" name="userRadio" value='<s:property value="USR_AMLUSERNAME"/>' /></td>
<td><s:property value="USR_AMLUSRID"/></td>
<td><s:property value="USR_AMLUSERNAME"/></td>
<td><s:property value="USR_ROLEID"/></td>
<td><s:property value="USR_LOCATIONID"/></td>
</tr>
</s:iterator>
</tbody>
</table>
有什么方法可以避免在同一个主jsp上使用两个jsp来刷新和刷新jsp?
您必须给您的表一个ID:
<table width="100%" id="myTable">
...
</table>
并调整您的AJAX调用:
$.ajax({
url: 'originalPage', // use original page here
type: 'POST',
data: { userId: userId },
dataType: 'html',
success: function (html) {
// get the content of #myTable from the AJAX result
var tableContent = $("#myTable", html).html();
// set the content of #myTable to the result of the AJAX call
$('#myTable').html(tableContent);
},
error: function(xhr, ajaxOptions, thrownError){
alert('An error occurred! ' + thrownError);
}
});
jQuery可以将要使用的目标作为第二个参数,该参数在$("#myTable", html)
中使用。这样,它就不会在当前文档中搜索#myTable
,而是搜索AJAX调用返回的文档。
这样做的缺点是整个原始页面需要通过AJAX加载,尽管只使用了其中的一小部分。
相关文章:
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- 如何在未直接触发的情况下停止事件
- 在不使用JQuery的情况下隐藏DOM中的选定元素
- 在不使用jquery的情况下查找页面中的所有锚点并附加函数
- 在不打开聊天屏幕的情况下制作Zopim-ding代理
- 在不阻止默认行为的情况下检测IE10中的缩放
- 如何在不传递此信息的情况下查找被调用的元素
- 如何在不刷新页面的情况下更新显示框
- 有没有一种方法可以在控制台关闭的情况下让console.log()在IE中记录消息
- 在不重新加载页面的情况下,从JSP(服务器端)b设置一个JavaScript变量
- 如何在不使用 jquery 刷新页面的情况下保持在同一 jsp 页面实例上
- 在 jsp 中,如何在有条件的情况下进行加载
- JSP下拉列表选择默认情况下使用struts加载页面的第一个选项
- 如何在没有任何事件的情况下调用jsp中的javascript函数
- 如何在不创建单独的jsp的情况下刷新表
- 在不刷新的情况下更新jsp页面的内容
- 如何在不使用表单的情况下从jsp调用servlet
- HTML和JSP—如何在不移动到另一个页面的情况下启动表单上的操作
- 在不刷新页面的情况下提交JSP后发出javascript警报
- 在不需要大量编码的情况下对JSP应用程序进行分页的最有效解决方案是什么?