日期:2014-05-17 浏览次数:20520 次
<script language="jscript" type="text/javascript">
var xmlHttp;
function CreateXmlHttp()
{
//创建对象
if (window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
//加载数据所在的服务器
var url = window.location.href + "/TestDiv";
xmlHttp.open("post", url, true);
xmlHttp.onreadystatechange = Way;
xmlHttp.send(null);
}
function Way()
{
if (xmlHttp.readystate == 4 && xmlHttp.status == 200)
{
document.getElementById("BindData").innerHTML = xmlHttp.responseText;
}
}
</script>
<div id="BindData">
</div>
<input id="Button1" type="button" value="重新绑定" onclick="CreateXmlHttp()"/>
[WebMethod()]
public static string TestDiv()
{
return "ajax局部刷新!";
}
$.ajax({
type: "post",
url: "test.aspx/TestDiv",
data: "{}",
cache: false,
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function(data) {
alert(data.d);
}
});