这是AJAX代码
$.ajax({
url:"searchTip",
type:"GET",
data:{"word":$("#a").val()},
dataType:"json",
complete:function(){
alert("fuck");
},
success:function (data){
alert(data[0]);
}
})
Servlet代码
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String keyword = req.getParameter("word");
CatalogService catalogService=new CatalogService();
List<Product> list=catalogService.searchProductList(keyword);
resp.setContentType("application/json;charset=utf-8");
PrintWriter out= resp.getWriter();
JSONArray json=JSONArray.fromObject(list);
out.print(json.toString());
out.flush();
out.close();
}