显式提交/隐式提交 //ajax方式的隐式提交
Posted 代我向西贝问好
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了显式提交/隐式提交 //ajax方式的隐式提交相关的知识,希望对你有一定的参考价值。
//创建jqueryAjax.html文件
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>//将js文件jquery-1.11.3.min.js导入到文件夹JS中
<script>
function fn1(){
$.get(
"/day480/ajaxJquery",
{"name":"qiang","age":20},
function(data){
alert(data.name)
},
"json"
);
}
function fn2(){
$.post(
"/day480/ajaxJquery",
{"name":"tong","age":21},
function(data){
alert(data.name)
},
"json"
);
}
function fn3(){
$.ajax({
url:"/day480/ajaxJquery",
async:true,
type:"POST",
data:{"name":"zhangyi","age":19},
success:function(data){
alert(data.name)
},
error:function(){
alert("请求失败");
},
dataType:"json"
});
}
</script>
</head>
<body>
<input type="button" value="显式提交 " onclick="fn1()"><span id="span1"></span>
<input type="button" value="隐式提交 " onclick="fn2()"><span id="span2"></span>
<input type="button" value="ajax隐式提交 " onclick="fn3()"><span id="span3"></span>
</body>
</html>
//创建servlet AjaxJquery ajaxJquery
package Demo;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AjaxJquery extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
String age = request.getParameter("age");
System.out.println(name+ " " +age);
response.setContentType("text/html;charset=utf-8");
response.getWriter().write("{"name":"tou头强","age":22}");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
以上是关于显式提交/隐式提交 //ajax方式的隐式提交的主要内容,如果未能解决你的问题,请参考以下文章
Mysql 说:#1422 - 存储函数或触发器中不允许显式或隐式提交
MySQL #1422 存储函数或触发器中不允许显式或隐式提交