qq_45818614
qq_45818614
2021-01-24 17:05

ajax请求不成功,总是500错误

  • json
  • ajax
  • jquery

这是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();
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答