前端:
$.ajax({
type:"get",
async: false,//是否非同步
url:"http://ip:連接埠/servlet位址",
dataType: "json",content : "application/x-www-form-urlencoded;charset=UTF-8",
jsonpCallback: "callback",
data: { }, //傳遞的參數
success: function(e){
//傳遞的參數
success: function(e){
//傳遞的參數
suvarem = $ .parseJSON(e);//e:傳回值
},
error: function(XMLHttpRequest, textStatus, errorThrown) {}
});
後台例:用servlet做的範例callback");//回呼函數
request.setCharacterEncoding("utf-8");//防止中文亂碼
response.setCharacterEncoding("utf-8");//防止中文亂碼
/response.Header(/response" pragma", "no-cache");
//response.setHeader("cache-control", "no-cache");
//list要回傳的結果
JSON
= JSONArray.fromObject(list); response.getWriter().print(callback+"('"+jsonArray+"')");