内容如下:
<form>
<table>
<tr>
<td>编号:</td>
<td><input type='text' name='bookId' id='bookId'/>
<input type='button' value='提取'onclick='return check();'/>
</td>
</tr>
<tr>
<td>价格:</td><td><input type='text' id='bookPrice' value=''/></td>
</tr>
</table>
</form>function check(){
}
单击 提取按钮时通过check () 方法调用 数据库 把 价格填到该页面价格的文本框中?
<form>
<table>
<tr>
<td>编号:</td>
<td><input type='text' name='bookId' id='bookId'/>
<input type='button' value='提取'onclick='return check();'/>
</td>
</tr>
<tr>
<td>价格:</td><td><input type='text' id='bookPrice' value=''/></td>
</tr>
</table>
</form>function check(){
}
单击 提取按钮时通过check () 方法调用 数据库 把 价格填到该页面价格的文本框中?
解决方案 »
- MyEclipse无法部署项目
- POI操作excel求和问题,求大神指教!!
- No WebApplicationContext found: no ContextLoaderListener registered?
- 刚学web开发..有点问题不太理解..望高手解释一下!
- 小女子不才,接触J2EE/EJB不久碰到的问题!跪求帮助!!!
- JPQL的全连接查询
- 第一个jsp --helloworld出错了????????
- 关于STRUTS安全的问题?
- 新手问题
- r如何在数据库随机取N条数据
- java 内存地址 通过 jni 能获得到吗 在线等 100分
- 菜鸟struts的logindemo页面出不来 求指教
这有个AJAX的例子,在xmlHttp.readyState == 4里面,给bookPrice赋值
<head>
<script src="jquery.js"></script>
<script>
(function($) {
$.fn.formLoad = function(p) {
var form = $(this);
var opts = {
url : 'data.json',
onSuccess : function(data){
form.find('input[type=text]').each(function() {
var id = $(this).attr('id') || $(this).attr('name');
$(this).val(data[id] || '');
});
}
}
$.extend(opts,p); $.post(opts.url,opts.onSuccess,'json');
}
})(jQuery);$(document).ready(function(){
$('#btn_getData').click(function() {
$('form').formLoad({ url : 'data.json' });
});
});
</script>
</head> <body>
<form>
<table>
<tr>
<td>编号:</td>
<td><input type='text' name='bookId' id='bookId'/>
<input type='button' value='提取' id="btn_getData"/>
</td>
</tr>
<tr>
<td>价格:</td><td><input type='text' id='bookPrice' value=''/></td>
</tr>
</table>
</form>
</body>
</html> 假定服务器返回的数据(data.json):{
"bookId" : "this is bookId",
"bookPrice" : "this is bookPrice"
}
<script language="javascript">
function model_vote(modelId){
var action = "/topics/2011guangzhou/modelVote.auto?modelId="+modelId;
$.ajax({
type:"post",
url:action,
dataType:"text",
async:"false",
error: function(){
alert('操作失败,数据错误');
},
success:function(count){
if(count!=null && count.length<10){
var input = $("b[id='voteModel_"+modelId+"']");
$.each(input,function(entryIndex,entry){
entry.innerHTML=count+"票";
});
}
}
});
}
</script>
<h4>
${model.modelName}
<b id="voteModel_${model.modelId}">${model.modelClickCount}票</b>
<input type="button" onclick="javascript:model_vote(${model.modelId})" value="我喜欢" />
</h4>这段代码希望对你有帮助
$.ajax({
type:"post",
url:action,
dataType:"text",
async:"false",
error: function(){
alert('操作失败,数据错误');
},
success:function(count){
if(count!=null && count.length<10){
var input = $("b[id='voteModel_"+modelId+"']");
$.each(input,function(entryIndex,entry){
entry.innerHTML=count+"票";
});
}
}
});
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache");
%>
<script type="text/javascript">
var xmlHttp;
function push(url) {
var urlReq = url;
sendRequest(urlReq);
} //创建XMLHttpRequest对象
function createXMLHttpRequest() {
if (window.XMLHttpRequest) { //Mozilla 浏览器
XMLHttpReq = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE浏览器
try {
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
}
}
}
} //发送请求函数
function sendRequest(url) {
createXMLHttpRequest();
XMLHttpReq.open("GET", url, true);
XMLHttpReq.onreadystatechange = processResponse;//指定响应函数
XMLHttpReq.send(null); // 发送请求
} //处理返回信息函数
function processResponse() {
if (XMLHttpReq.readyState == 4) { // 判断对象状态
if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息
var result = XMLHttpReq.responseText;
document.getElementById("main").innerHTML = result;
} else { //页面不正常
window.alert("您所请求的页面有异常。");
}
}
}
</script>如上面的代码,是我写的一个例子,是可以正常实现Ajax的无页面刷新的。
有几个注意的,最上面的<% %>是禁止Jsp页面缓存还有就是这段JS代码,如果我写在一个JS文件里,然后Jsp调用的话,貌似会有些小问题。好了,互相研究,呵呵 祝楼主能解决问题!