<input type="button" value="同步" id="bt1" /> <input type="button" value="异步" id="bt2" /> $("#bt1").click(function () { $.ajax({ type: "post", url: "test", cache:false, async:false, success: function(data){ alert(data); } }); $("#bt2").click(function () { $.ajax({ type: "post", url: "test", cache:false, async:true, success: function(data){ alert(data); } }); }); }); @WebServlet("/test") public class TestServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { Thread.sleep(5000); resp.getWriter().write("test"); } catch (InterruptedException e) { e.printStackTrace(); } } } |
图片1.png (45.58 KB, 下载次数: 59)
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |