利用jquery使用ajax

因为某些兼容性的问题,我们通常会使用jquery来写ajax,要使用jquery首先我们需要导入jquery.

<script type="text/javascript" src="http://localhost:8080/jquery_test/jquery.js"></script>

以下是html代码

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>first web</title>
<link rel="stylesheet" href="./index.css">
<script type="text/javascript" src="http://localhost:8080/jquery_test/jquery.js"></script>
<script src="http://localhost:8080/jquery_test/test.js"></script>
</head>
<body>
<div>
	<h1 id="g1">欢迎进入我的网站</h1>
	<div id="k1">
		<form action="">
		<div>内容:<textarea name="content" rows="8" cols="30" id="content"></textarea></div>
		<div id="ss"></div>
		</form>
		<button id="t1">点击</button>
		<p></p>
	</div>
</div>	
</body>
</html>

以下是js代码

$(function(){
$("#t1").click(function(){
$.ajax({
	url:"http://localhost:8080/jquery_test/Use_ajax",
	error:function(){
	alert("请求失败");
	},
	success:function(data){
	alert(JSON.stringify(data));
	alert(new Date());
	},
	type:"get",
	dataType:"json",
	data:{
		a:18,
		name:17,
		date:new Date()
	}
});
});
});

url:请求地址
error:请求失败响应
success:请求成功响应
type:响应类型
dataType:返回类型,一般为json型或字符串型
data:传参,格式为json格式
java代码和上一期使用ajax一样

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值