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異步請求的示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。
新聞熱點
疑難解答