jquery jsp教程儲存資料代碼
jquery代碼
$().ready(function(){
var url="/admin/ajaxGetNewsClassFather.do";
var pars="random="+Math.random();
var newsClassFather= $('#newsClassFather');
$.ajax({
url : url,
data : pars,
type :"POST",
success :function(res){
newsClassFather.append(res);
}
});
});
jsp代碼
RequestMapping("/admin/ajaxGetNewsClassFather.do")
public void ajaxGetNewsClassFather(Writer writer, Model model, HttpServletRequest request, HttpServletResponse response)
{
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
String dbname= CookieUtil.getDBname(request, response);
List<NewsClass> newsClassList= newsClassJdbcService.findbyBclassid(dbname,0);
String result="";for (NewsClass newsClass : newsClassList)
{
result+="<option value='"+ newsClass.getClassid()+"'>"+ newsClass.getClassname()+"</option>";
}try
{
writer.write(result);
}catch (IOException e)
{
e.printStackTrace();
}
}