您的位置:首页 > Web前端 > JQuery

Jquery Ajax 使用备忘

2016-04-20 14:12 363 查看
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="ext/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function ajaxSubmit() {
$.ajax({
url : "http://localhost:8080/RESTfulWSDemo/services/helloWorld", //请求的url地址
dataType : "json", //返回格式为json
async : true, //请求是否异步,默认为异步,这也是ajax重要特性
data : {
"username" : "Ajax提交请求"
}, //参数值
type : "get", //请求方式
cache: false,
dataType:'html',
beforeSend : function() {
//请求前的处理
alert("请求前");
},
success : function(data) {
alert(data);
//请求成功时处理
alert("成功");
},
complete : function() {
//请求完成的处理
alert("完成");
},
error : function() {
//请求出错处理
alert("错误");
}
});

}
</script>
</head>

<body>
This is my JSP page.
<br>

<form action="">
<input type="button" onclick="ajaxSubmit();" value="提交">
</form>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: