1. ajax 在 数据库 数据”删除 “ 操作上还是有优势的;
Jsp: <script type="text/javascript">
function func(id){
var url="ExerciseTest_delebyidTest";
$.ajax({
url:url,
dataType : "json",
data:{stId:id},
success : function(data) {
alert(JSON.stringify(data));
window.location.reload(); 重载一下,就是 刷新
},
});
}
</script>
这是 有 foreach 遍历出来的 一行,
<span class="fas" onclick="func('${bvss.testId}')">
删除
</span>
action上面 是:
private String msgs;-------get set
// ajax 的鬼
public String delebyidTest(){
exerciseTestServiceImpl.deletezhongjianbiao(stId);
msgs="删除成功";
return "ajax2";
}
xml 里面 的 配置 就是 注解 就是:@Json(name="msg") 不传 的 就是 @Json(serizilabl="false")
<result name="ajax2" type="json">
<param name="includeProperties">
msgs ----还可以是 集合的 那些,注意 要 限制 \[\+\d]\
</param>
</result>
,,,,,,,,,,,,,,,
对于 应用 ajax 进行 form 表单的 提交 会十分的 麻烦,需要 向 拼接字符串一样 把他们 搞一下,
<script type="text/javascript">
function func2(id){
var html="";
var url="ExerciseTest_updatebyidTest";
$.ajax({
url:url,
dataType : "json",
data:{stId:id},
success : function(data) {
//alert(JSON.stringify(data));
html="请修改:<br/><form action='ExerciseTest_trueupdateby.action' method='post'>";
html+="卷子名字:<input id= "+data.testId+" name='tests.testName' value= "+data.testName+" />";
html+="<input type='hidden' name='tests.testId' value= "+data.testId+" />";
html+="<br/> 分数:<input type='text' name='tests.score' value= "+data.score+" />";
html+="</br><input type='submit' value= '提交' />";
html+="</form>";
$("#spsps").append(html);
//window.location.reload();
},
});
}
</script>
由于 会先把 id 传过去 拿到一个 Test 对象
所以 在 xml这边 需要 做 一个 转化 说明
<result name="ajax3" type="json">
<param name="root">tests</param> ---------对象
<param name="includeProperties">
testId,testName, ----------对象中的 属性 在
difficulty, ajax 中取出来 就是 data.joinTime
joinTime,
testType,
principleType,
answer,
isExec,
testTitle,
score,
</param>
</result>
1万+

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



