以下为S2。
跟普通的地方不同的是要回调
dataType : "jsonp",
jsonp : "callBack",
jsonpCallback : "success_back",
callBack需写getter setter.
function getTeacher(id) {
try{
$.ajax({
url : "http://b.com/res/test!getName.action",
type : "get",
data : {
"id" : id
},
async: true,
dataType : "jsonp",
jsonp : "callBack",
jsonpCallback : "success_back",
success : function(result) {
alert(result[0].name);
},
error : function(error) {
}
});
}catch(err){
}
}
public String getTeacherByPointId() {
try {
String result = callBack;
HttpServletResponse response = this.getServletResponse();
String tName = teacherService.getTeacherById(videoPointId);
response.setContentType("text/plain");
response.setCharacterEncoding("utf-8");
response.getWriter().write(result+"([{'name':'"+tName+"'}])");
} catch (Exception e) {
logger.error("error",e);
}
return null;
}