$.ajax({
type: "POST",
url:"${ctx}/credit-server/CalculationCtrl/Calculation.do?type="+ type11+"&moneys="+type13+"&periods="+typeText1+"&thinkTurnDate="+thinkTurnDate,
data: "",
success: function (data) {
var strHtml = ''
//data为后天传过来的数据源。json对象
for(var i = 0i<data.lengthi++){
alert(date[i])//d出后台数据
strHtml = strHtml + '<td>+'data[i]+'<td>'
}
$('#标签id').html(strHtml)
}
error:funciton(){
alert('出错')
}
})
1新建一个servlet xml中相应配置(一般自动)2创建service方法
3接受参数,做 *** 作,返回数据
比如页面发送ajax请求到SomeServlet
$.post("SomeServlet的请求路径",{param:"param"},function(data){//data为返回的e799bee5baa6e997aee7ad94e58685e5aeb931333337613931数据以json形式alert(data.id + " " + data.name + " " + data.age )},"json")
Servlet
public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {request.setCharacterEncoding("utf-8") response.setContentType("text/htmlcharset=utf-8") PrintWriter out = response.getWriter() String param = request.getParameter("param")//获取参数//你的 *** 作//返回数据String json = "{\"id\":1,\"name\":\"张三\",\"age\":18}" out.print(json)}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)