ajax强大,但一大堆js包未免复杂,对于页面中一小点的ajax应用,iframe亦可很容易地做到:
1. 首先定义一个不可见的iframe:
[code]<iframe id="hiddenFrame" width=0 height=0></iframe>[/code]
2. 定义触发函数:
[code]function detectUserName() {
var url = "detect_user_name.action?member.loginId=" + document.getElementById("member.loginId").value;
document.getElementById("hiddenFrame").src=url;
}[/code]
3. 触发按钮
[code]<input type="button" id="detectUserNameButton" value="检测用户名" onclick="detectUserName();">[/code]
4. detect_user_name.action的result页面中利用js来弹出结果信息
1. 首先定义一个不可见的iframe:
[code]<iframe id="hiddenFrame" width=0 height=0></iframe>[/code]
2. 定义触发函数:
[code]function detectUserName() {
var url = "detect_user_name.action?member.loginId=" + document.getElementById("member.loginId").value;
document.getElementById("hiddenFrame").src=url;
}[/code]
3. 触发按钮
[code]<input type="button" id="detectUserNameButton" value="检测用户名" onclick="detectUserName();">[/code]
4. detect_user_name.action的result页面中利用js来弹出结果信息
本文介绍了一种利用iframe实现简单AJAX请求的方法,通过定义不可见的iframe和触发函数,实现在不刷新页面的情况下获取并展示服务器返回的数据。
224

被折叠的 条评论
为什么被折叠?



