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); }
相关推荐
TONIYH 2020-07-22
83510998 2020-07-18
wcqwcq 2020-06-26
delmarks 2020-06-14
ppsurcao 2020-06-14
tthappyer 2020-06-07
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03