js代码:
$.ajax({
url:'http://120.56.45.45:8080/TestJsonp/servlet/GetLoginServlet',
dataType:'jsonp',
jsonp:'callback',
data:{//发送给servlet的数据
},
success: function(json){
alert(json.success);
}
});
servlet代码:
protected void doPost(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException {
String callback = req.getParameter("callback");
StringBuffer wr = new StringBuffer();
wr.append(callback + "(");
wr.append({\"success\":\"true\"});
wr.append(")");
PrintWriter out = resp.getWriter();
out.print(wr);
out.flush();
out.close();
}
原文链接:/json/289947.html