1.jQuery对Ajax的封装:load(),get(),post()
<div id="one"></div>
$("#b1").click(function(){
//load(responseurl,senddata,function(responseData,textStatus,xmlRequest))
$("#one").load("load01.jsp",{username:$("#username").val(),psw:$("#psw").val()},function(data,textStatus,xmlRequest){
});
});
load1.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%
System.out.println(request.getParameter("username");
System.out.println(request.getParameter("psw");
out.println("nihao");
%>
2.get 方式
<div id="one"></div>
$("#b1").click(function(){
var xmlReq=$.get("get.jsp",function(responseData,textStatus){
//将从服务器返回的数据添加到html中
$("#one").text(responseData);
});
alert(xmlReq.readyState);
alert(xmlReq.status);
});
get.jsp:
<%
System.out.println(request.getParameter("username");
System.out.println(request.getParameter("psw");
out.println("你好");
%>