Jquery Ajax 使用备忘



<%@ 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" οnclick="ajaxSubmit();" value="提交">
	</form>

</body>
</html>




猜你喜欢

转载自blog.csdn.net/kalision/article/details/51200401
今日推荐