轻云流火 chitry

你永远不知道未来的你有多强

jQuery中的Ajax实现




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ddd</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script language="JavaScript" src="../js/jquery-1.4.2.js">
</script>
<style type="text/css">
div, span {
width: 140px;
height: 140px;
margin: 20px;
background: #9999CC;
border: #000 1px solid;
float: left;
font-size: 17px;
font-family: Roman;
}
div.mini {
width: 30px;
height: 30px;
background: #CC66FF;
border: #000 1px solid;
font-size: 12px;
font-family: Roman;
}
div.visible {
display: none;
}
</style>
<!--引入jquery的js库-->
</head>
<body>
<form action="" name="form1" id="form1">
<input type="text" name="username" id="username" value="zhang">
<br>
<input type="text" name="psw" id="psw" value="99999">
<br>
<input type="button" id="b1" value="登陆">
</form>
<div id="one">
</div>
<h1></h1>
</body>
<script language="JavaScript">
$().ready(function(){
/*
* load(url,[data],[callback]);
* url:请求的服务器的资源地址
* data:向服务器端发送数据,JSON串格式.如果有此参数,就以POST方式提交数据,没有就是get方式提交数据
* callback:function(data,textStatus,xhr){}
* data:服务器端返回的数据
* textStatus:状态。succuss, error, notmodify, timeout
* xhr:XmlHttpRequest对象本身
*/
/*$("#b1").click(function(){
$("#one").load("1.jsp",{username:'gfy'},function(data,textStatus,xhr){
//alert(data);
//alert(textStatus);
//alert(xhr);
});
});*/
$("#b1").click(function(){
//1.jsp h1,h2 只获取1.jsp返回的h1、h2标记的内容
$("#one").load("1.jsp h1,h2",{username:'gfy'},function(data,textStatus,xhr){
$(":header").html(data);
});
});
});
</script>
</html>



//jsp文件:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
System.out.println(request.getMethod());
System.out.println(request.getParameter("username"));
out.write("ok");
%>



//第二种:get

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ddd</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script language="JavaScript" src="../js/jquery-1.4.2.js"></script>
</script>
<style type="text/css">
div, span {
width: 140px;
height: 140px;
margin: 20px;
background: #9999CC;
border: #000 1px solid;
float: left;
font-size: 17px;
font-family: Roman;
}
div.mini {
width: 30px;
height: 30px;
background: #CC66FF;
border: #000 1px solid;
font-size: 12px;
font-family: Roman;
}
div.visible {
display: none;
}
</style>
<!--引入jquery的js库-->
</head>
<body>
<form action="" name="form1" id="form1">
<input type="text" name="username" id="username" value="zhang">
<br>
<input type="text" name="psw" id="psw" value="99999">
<br>
<input type="button" id="b1" value="登陆">
</form>
<div id="one">
</div>
</body>
<script language="JavaScript">
$().ready(function(){
$("#b1").click(function(){
/*
* $.get(url,data,callback)
*/
/*$.post("1.jsp",{username:'gfy',psw:'123'},function(data,textStatus){
$("#one").text(data);
});*/
$.post("1.jsp",$("#form1").serialize(),function(data,textStatus){
$("#one").text(data);
});
});
});
</script>
</html>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ddd</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script language="JavaScript" src="../js/jquery-1.4.2.js">
</script>
<style type="text/css">
div, span {
width: 140px;
height: 140px;
margin: 20px;
background: #9999CC;
border: #000 1px solid;
float: left;
font-size: 17px;
font-family: Roman;
}
div.mini {
width: 30px;
height: 30px;
background: #CC66FF;
border: #000 1px solid;
font-size: 12px;
font-family: Roman;
}
div.visible {
display: none;
}
</style>
<!--引入jquery的js库-->
</head>
<body>
<form action="" name="form1" id="form1">
<input type="text" name="username" id="username" value="zhang">
<br>
<input type="text" name="psw" id="psw" value="99999">
<br>
<input type="button" id="b1" value="登陆">
</form>
<div id="one">
</div>
<h1></h1>
</body>
<script language="JavaScript">
$().ready(function(){
/*
* load(url,[data],[callback]);
* url:请求的服务器的资源地址
* data:向服务器端发送数据,JSON串格式.如果有此参数,就以POST方式提交数据,没有就是get方式提交数据
* callback:function(data,textStatus,xhr){}
* data:服务器端返回的数据
* textStatus:状态。succuss, error, notmodify, timeout
* xhr:XmlHttpRequest对象本身
*/
/*$("#b1").click(function(){
$("#one").load("1.jsp",{username:'gfy'},function(data,textStatus,xhr){
//alert(data);
//alert(textStatus);
//alert(xhr);
});
});*/
$("#b1").click(function(){
//1.jsp h1,h2 只获取1.jsp返回的h1、h2标记的内容
$("#one").load("1.jsp h1,h2",{username:'gfy'},function(data,textStatus,xhr){
$(":header").html(data);
});
});
});
</script>
</html>



//jsp文件:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
System.out.println(request.getMethod());
System.out.println(request.getParameter("username"));
out.write("ok");
%>



//第二种:get

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ddd</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script language="JavaScript" src="../js/jquery-1.4.2.js"></script>
</script>
<style type="text/css">
div, span {
width: 140px;
height: 140px;
margin: 20px;
background: #9999CC;
border: #000 1px solid;
float: left;
font-size: 17px;
font-family: Roman;
}
div.mini {
width: 30px;
height: 30px;
background: #CC66FF;
border: #000 1px solid;
font-size: 12px;
font-family: Roman;
}
div.visible {
display: none;
}
</style>
<!--引入jquery的js库-->
</head>
<body>
<form action="" name="form1" id="form1">
<input type="text" name="username" id="username" value="zhang">
<br>
<input type="text" name="psw" id="psw" value="99999">
<br>
<input type="button" id="b1" value="登陆">
</form>
<div id="one">
</div>
</body>
<script language="JavaScript">
$().ready(function(){
$("#b1").click(function(){
/*
* $.get(url,data,callback)
*/
/*$.post("1.jsp",{username:'gfy',psw:'123'},function(data,textStatus){
$("#one").text(data);
});*/
$.post("1.jsp",$("#form1").serialize(),function(data,textStatus){
$("#one").text(data);
});
});
});
</script>
</html>
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_29025139/article/details/46795871
文章标签: Ajax js 互联网 jQuery
个人分类: Web启示录 [基础篇]
想对作者说点什么? 我来说一句

JQuery实现ajax上传文件示例源码

2013年01月31日 47KB 下载

没有更多推荐了,返回首页

不良信息举报

jQuery中的Ajax实现

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭