前端:
$.ajax({
type:"get",
async: false,//是否异步
url:"http://ip:端口/servlet地址",
datatype: "jsonp",
contenttype: "application/x-www-form-urlencoded;charset=utf-8",
jsonpcallback: "callback",
data: { }, //传递的参数
success: function(e){
var r = $.parsejson(e);//e:返回值
},
error: function(xmlhttprequest, textstatus, errorthrown) {}
});
后台:用servlet做的样例
string callback = request.getparameter("callback");//回调函数
request.setcharacterencoding("utf-8");//防止中文乱码
response.setcharacterencoding("utf-8");//防止中文乱码
//response.setheader("pragma", "no-cache");
//response.setheader("cache-control", "no-cache");
//list要返回的结果
jsonarray jsonarray = jsonarray.fromobject(list);
response.getwriter().print(callback+"('"+jsonarray+"')");
response.getwriter().flush();
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号