ajax 简单操作

 
<script>
$(function () {
//$("#send").click(function () {
// $.get("JQuery.ashx", { username: $("#username").val(), content: $("#content").val() }, function (msg) {
// $("#resText").html(msg);
// });
//});
$("#send").click(function () {
$.post("JQuery.ashx", { username: $("#username").val(), content: $("#content").val() }, function (msg) {
$("#resText").html(msg);
});
});
});
</script>
<body>
<form id="form1" action="#">
<p>评论:</p>
<p>姓名:<input type="text" name="username" id="username" /></p>
<p>内容:<textarea name="content" id="content" rows="2" cols="20"></textarea></p>
<p><input type="button" name="name" value="提交 " id="send" /></p>
</form>
<div class="comment">
已有评论
</div>
<div id="resText">
</div>
</body>
第二种
<html><!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc() {
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "WebForm2.aspx", true);
xmlhttp.send();
}
</script>
</head>
<body> <div id="myDiv"><h2>使用 AJAX 修改该文本内容</h2></div>
<button type="button" onclick="loadXMLDoc()">修改内容</button> </body>
</html>
w3cSchool.cc
转载自
http://www.cnblogs.com/dyxd/p/4261364.html
上一篇:缓存技术比拼:Redis与Memcached的同与不同


下一篇:phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接。您应该检查配置文件中的主机、用户名和密码