2008-07-01
运用ajax prototype框架注意事项
关键字: prototype
今天无聊,随便看了下prototype,觉得挺简单的,于是写了个简单的sample,供以后参考。
首先页面的代码如下:
然后是关于spring的配置文件,没什么可说的!
最后特别要注意的是action的问题
写的不全,如果有什么不懂的自己多试试就明白了,呵呵。
我本来想把源代码传上来,可我们公司不能上传,郁闷!
首先页面的代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<SCRIPT LANGUAGE="JavaScript">
<!--
function ajaxTest(test){
code = event.keyCode;
if(code == 13){
var f = document.getElementById('TheForm');
if(f.searchhhNo.value != ''){
var url = 'login.do?method=ajaxTest&userName='+test.value ;
new Ajax.Request(url, { method: "get",
parameters:Form.serialize('theForm'),
onSuccess: function(httpObj){
ajaxText = httpObj.responseText;
alert(ajaxText);
hhpnResult(ajaxText);
},
onFailure: function(httpObj){
alert(httpObj.statusText);
}
});
}
}
}
function hhpnResult(msg){
if(msg != null){
var f = document.getElementById('theForm');
f.username.value = msg;
}else{
alert('无法找到相关资料');
}
}
</SCRIPT>
<html>
<body>
<form name="theForm" action="login.do">
<p align="center">
ajax測試
</p>
<br>
用戶名:
<input type="text" name="username" onkeydown="ajaxTest(this)" />
<br>
密 碼:
<input type="password" name="password">
<br>
<p>
<input type="submit" value="提交" >
<input type="reset" value="重設" >
</p>
</form>
</body>
</html>
然后是关于spring的配置文件,没什么可说的!
最后特别要注意的是action的问题
public ModelAndView applyFpr(HttpServletRequest request,HttpServletResponse response,LoginFormBean formBean){
String returnResult = "";
....
//特別注意,要不然得不到responseText的数值,或者得到的是整个页面的html代码
response.setContentType("text/html; CHARSET=utf-8");
try {
response.getWriter().write(returnResult);
} catch (IOException e) {
e.printStackTrace();
}
}
写的不全,如果有什么不懂的自己多试试就明白了,呵呵。
我本来想把源代码传上来,可我们公司不能上传,郁闷!
发表评论
- 浏览: 43784 次
- 性别:

- 来自: 深圳

- 详细资料
搜索本博客
最新评论
-
美国梦八夺冠已成定局了!
梦八队员的运动能力太强了,抢断和快攻水平一流,往往能在某一段时间打出小高潮,把比 ...
-- by suyulin6688 -
美国梦八夺冠已成定局了!
robbin 写道keshin 写道robbin 写道美国就快攻一招鲜,如果碰上 ...
-- by keshin -
美国梦八夺冠已成定局了!
keshin 写道robbin 写道美国就快攻一招鲜,如果碰上实力强劲,内线有高 ...
-- by robbin -
美国梦八夺冠已成定局了!
keshin 写道robbin 写道美国就快攻一招鲜,如果碰上实力强劲,内线有高 ...
-- by zxpole -
美国梦八夺冠已成定局了!
robbin 写道美国就快攻一招鲜,如果碰上实力强劲,内线有高度,外线防守又好的 ...
-- by keshin






评论排行榜