日期:2014-05-16 浏览次数:20723 次
$.ajax({
type: "POST",
url: "/xxx/ReturnJson",
data: "name=John&location=Boston",
dataType:"json",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
public ActionResult ReturnJson()
{
return "json字符串";
}
$.ajax({
type: "POST",
url : "videoSec_findBySid.action",
data: "sid="+sid ,
success: function(msg){
var data = eval(msg) ;
},
async:false
});
public void findBySid()throws Exception{
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String sid = request.getParameter("sid") ;
VideoSec vs = videoSecService.findBySid(Integer.parseInt(sid)) ;
String jsonData = "["+toJson(vs)+"]" ;
out.print(jsonData) ; //json数据传给前台
out.flush() ;
out.close() ;
}