js:
$.ajax({
url: '',
data: {},
dataType: "jsonp",
jsonp: "jsoncallback",
async: false,
type: 'get',
success: function (data) {
console.log(data)
}
})
// type 必须是 get
// jsonp 和后台定义统一 jsoncallback
java:
public void test(String meetingId, HttpServletRequest request, HttpServletResponse response) {
String jsoncallback = request.getParameter("jsoncallback");// 客户端请求参数
String result = "";
JSONArray json=JSONArray.fromObject(list);
//System.out.println(jsoncallback+"("+json+")");
result = jsoncallback + "("+json+")";
try {
response.getWriter().print(result);
} catch (IOException e) {
e.printStackTrace();
}
}