ajax怎么动态加载json数据
这篇文章将为大家详细讲解有关ajax怎么动态加载json数据,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
创新互联基于10余年网站建设行业经验,一直致力于为中小型企业提供信息化解决方案,创新互联做到开放、开源,让企业所有核心数据掌握到企业手里,打破行业乱象,让企业被网络公司掌控的局面不再发生;美工设计部,产品/程序研发部,营销策划部,售后客服部。一切服务为企业量身定制,专注为您!
jsp代码
servlet代码
//get public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String name = request.getParameter("name"); String age = request.getParameter("age"); if (name == null || name == "") { name = "测试名字admin"; } if (age == null || age == "") { age = "测试年龄100"; } user user = new user(1, name, age); PrintWriter out = response.getWriter(); JSONObject jsonObj = JSONObject.fromObject(user); out.print(jsonObj); out.flush(); out.close(); }
//post public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // response.setContentType("text/html"); request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String name = request.getParameter("name"); if (name == null || name == "") { name = "测试名字admin"; } String age = request.getParameter("age"); if (age == null || age == "") { age = "测试年龄100"; } user user = new user(1, name, age); PrintWriter out = response.getWriter(); JSONObject jsonObj = JSONObject.fromObject(user); out.print(jsonObj); out.flush(); out.close(); }
JS核心代码
关于ajax怎么动态加载json数据就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
新闻标题:ajax怎么动态加载json数据
路径分享:http://pwwzsj.com/article/ggsppg.html