Jquery ajax load(),get(),post()

//load()用来加载html文档中的代码片段,添加到指定元素内部

//如果只加部分选定的元素可以.load("url 选择器")
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<input id="send" type="button" value="AJAX提交"/>
<p id="resText"></p>
</body>
<script src="../js/jquery-1.11.3.js"></script>
<script>
$(function(){
$("#send").click(function(){
$("#resText").load("text.html")
});
});
</script>
</html>
//如果有参数传递,会自动转为post方式
//$("#resText").load("text.html",{name:"",age:''},function(){})
//$("#resText").load("text.html",{name:"",age:''},function(responseText,textStatus,XMLHttpRequest){})
//回调函数的参数分别代表返回内容、请求状态和XMLHttpRequest对象
//responseText返回的内容可以说XML文档,json文件,html片段
//textStatus请求状态为success,error,notmodified,timeout4种
//HTML片段返回
$(function(){
$("#send").click(function(){
$.get("get1.php",{
username:$("#username").val(),
content: $("#content").val()
},function(data,textStatus){
$("#resText").html(data);
},"json")
})
})
$(function(){
$("#send").click(function(){
$.post("post1.php",{
username:$("#username").val(),
content: $("#content").val()
},function(data,textStatus){
$("#resText").append(data);
})
});
});
原文地址:https://www.cnblogs.com/dianzan/p/7373935.html