本文主要为大家带来一篇jquery请求servlet实现ajax异步请求的示例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望能帮助到大家。
ajax可以发送异步请求实现无刷新效果,但是使用javascript比较麻烦,就query提供了一些封装的方法 ,可以使得操作更为简单:
$.ajax()方法:
function sendRequest() { $.ajax({ url: "Hello", type: "GET", dataType: "txt", data: "name=zhangsan", complete: function(result){ alert(result.responseText); } }); }
$.get()方法:
function sendRequestByGet(){ $.get("Hello","name=lisi",function(result){ alert(result); }); }
$.post()方法:
function sendRequestByPost(){ $.post("Hello","name=wangwu",function(result){ alert(result); }); }
$.load()方法:
//load代码等效使用如下$get()方法 /* $get(url, data, function(result){ //将result数据填充到页面元素中 $(“#h2”).html(result); }); */ function load(){ $("h2").load("Hello","name=hahaha"); }
以上异步请求的Hello文件:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String name=req.getParameter("name"); resp.getWriter().print(name); }
相关推荐:
以上就是jquery请求servlet实现ajax异步请求实例分享的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号