var configObj = {
method //数据的提交方式:get和post
url //数据的提交路劲
async //是否支持异步刷新,默认是true
data //需要提交的数据
dataType //服务器返回数据的类型,例如xml,String,Json等
success //请求成功后的回调函数
error //请求失败后的回调函数
}
$.ajax(configObj);//通过$.ajax函数进行调用。
var configObj = {
method //数据的提交方式:get和post
url //数据的提交路劲
async //是否支持异步刷新,默认是true
data //需要提交的数据
dataType //服务器返回数据的类型,例如xml,String,Json等
success //请求成功后的回调函数
error //请求失败后的回调函数
}
$.ajax(configObj);//通过$.ajax函数进行调用。
<span style="font-size:18px;"> // 删除
$.ajax({
type : "POST", //提交方式
url : "${pageContext.request.contextPath}/org/doDelete.action",//路径
data : {
"org.id" : "${org.id}"
},//数据,这里使用的是Json格式进行传输
success : function(result) {//返回数据根据结果进行相应的处理
if ( result.success ) {
$("#tipMsg").text("删除数据成功");
tree.deleteItem("${org.id}", true);
} else {
$("#tipMsg").text("删除数据失败");
}
}
});
</span>
<span style="font-size:18px;"> $(function(){
var options = {
beforeSubmit : function() {//处理以前需要做的功能
$("tipMsg").text("数据正在保存,请稍候...");
$("#insertBtn").attr("disabled", true);
},
success : function(result) {//返回成功以后需要的回调函数
if ( result.success ) {
$("#tipMsg").text("机构保存成功");
//这里是对应的一棵树,后边会介绍到,
// 控制树形组件,增加新的节点
var tree = window.parent.treeFrame.tree;
tree.insertNewChild("${org.id}", result.id, result.name);
} else {
$("#tipMsg").text("机构保存失败");
}
// 启用保存按钮
$("#insertBtn").attr("disabled", false);
},
clearForm : true
};
$('#orgForm').ajaxForm(options); //通过Jquery.Form中的ajaxForm方法进行提交
});
</span>
<html>
<head>
<title>Traditional Ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function getDateTime() {
var xmlHttp;
if (window.XMLHttpRequest) {
// For IE7+, Firefox, Chrome, Opera, Safari
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// For IE6, IE5
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
document.getElementById("timediv").innerHTML = "现在时间" + xmlHttp.responseText;
}
}
xmlHttp.open("GET", "ajax.php", true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<div id="timediv">现在时间</div>
<br /><input type="button" value="测试传统的 Ajax" onClick="getDateTime()" />
</body>
</html>
<?php
//服务器端为格林尼治标准时间,这里需设置为中国所在时区
date_default_timezone_set("PRC");
echo date("Y-m-d H:i:s");
?>
<html>
<head>
<title>Traditional Ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js?ver=1.4.4"></script>
<script type="text/javascript">
function getDateTime() {
$("#timediv").load("ajax.php");
}
</script>
</head>
<body>
<div id="timediv"></div>
<br /><input type="button" value="测试 jQuery 的 Ajax" onClick="getDateTime()" />
</body>
</html>
$.get(url, [data], [callback]) $.post(url, [data], [callback], [type])
<html>
<head>
<title>jQuery Ajax (get and post)</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js?ver=1.4.4"></script>
<script type="text/javascript">
$(document).ready(function() {
// 为 GET 按钮添加事件
$("#getbtn").click(function() {
$.get("ajaxpage.php", {username:$("#username").val()}, function(data) {
$("#ajaxdata").html(data); // 将服务端返回的数据填充到 P 标签中
});
});
// 为 POST 按钮添加事件
$("#postbtn").click(function() {
$.post("ajaxpage.php", {username:$("#username").val()}, function(data) {
$("#ajaxdata").html(data); // 将服务端返回的数据填充到 P 标签中
});
});
});
</script>
</head>
<body>
你的大名:<input type="text" id="username" /><br />
<input type="button" id="getbtn" value="GET 方法" /><br />
<input type="button" id="postbtn" value="POST 方法" />
<p id="ajaxdata"></p>
</body>
</html>
<?php
// 服务器端为格林尼治标准时间,这里需设置为中国所在时区
date_default_timezone_set("PRC");
$username = "";
$ajaxMethod = "";
// 判断是 GET 还是 POST
if(isset($_GET["username"])) {
$username = $_GET["username"];
$ajaxMethod = "GET";
} else {
$username = $_POST["username"];
$ajaxMethod = "POST";
}
<script type="text/javascript">
$(document).ready(function() {
// 为 GET 按钮添加事件
$("#getbtn").click(function() {
$.ajax({
type: "GET",
url: "ajaxpage.php",
data: {username:$("#username").val()},
timeout: 3000,
error: function() {
alert("error!");
},
success: function(data) {
// 回调函数,将返回的数据添加到 P 标签中
$("#ajaxdata").html(data);
}
});
});
// 为 POST 按钮添加事件
$("#postbtn").click(function() {
$.ajax({
type: "POST", // Ajax 提交方式
url: "ajaxpage.php", // 提交页
data: {username:$("#username").val()}, // 要提交的数据
timeout: 3000, // 超时设置,单位为毫秒
error: function() { // Ajax 发生错误时
alert("error!");
},
success: function(data) {
// 回调函数,将返回的数据添加到 P 标签中
$("#ajaxdata").html(data);
}
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
// 全局 Ajax 设定,这里的设置将对本页面所有 Ajax 方法适用
$.ajaxSetup({
url: "ajaxpage.php", // Ajax 提交页
timeout: 3000, // 超时设置,单位为毫秒
error: function() { // Ajax 发生错误时
alert("error!");
}
});
// 为 GET 按钮添加事件
$("#getbtn").click(function() {
$.ajax({
type: "GET",
data: {username:$("#username").val()},
success: function(data) {
// 回调函数,将返回的数据添加到 P 标签中
$("#ajaxdata").html(data);
}
});
});
// 为 POST 按钮添加事件
$("#postbtn").click(function() {
$.ajax({
type: "POST", // Ajax 提交方式
data: {username:$("#username").val()}, // 要提交的数据
success: function(data) {
// 回调函数,将返回的数据添加到 P 标签中
$("#ajaxdata").html(data);
}
});
});
});
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有