这是JS语言
var xmlHttp = false;
try{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e1)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2)
{
xmlHttp = false;
}
}
}
function callServer()
{
var url = "PageName.aspx?Id=" + escape("zx");
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8');
xmlHttp.onreadystatechange=updatePage;
xmlHttp.send("Id=" + escape("zx"));//post提交时参数要放在这里 }
if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
{
xmlHttp = new XMLHttpRequest();
}
function updatePage()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var response = xmlHttp.responseText;
test1.innerHTML=response;
document.getElementsByName("test1").innerHTML="<span>response</span>";
}
}
}
这是显示的
<span style="padding:0 2px 0 2px; font-size:10pt; font-weight:bolder;" id="test1" class="xiahuaxian"> </span>
var xmlHttp = false;
try{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e1)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2)
{
xmlHttp = false;
}
}
}
function callServer()
{
var url = "PageName.aspx?Id=" + escape("zx");
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8');
xmlHttp.onreadystatechange=updatePage;
xmlHttp.send("Id=" + escape("zx"));//post提交时参数要放在这里 }
if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
{
xmlHttp = new XMLHttpRequest();
}
function updatePage()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var response = xmlHttp.responseText;
test1.innerHTML=response;
document.getElementsByName("test1").innerHTML="<span>response</span>";
}
}
}
这是显示的
<span style="padding:0 2px 0 2px; font-size:10pt; font-weight:bolder;" id="test1" class="xiahuaxian"> </span>
下面给你一个示例:<script>
var xmlHttp = null;
(function(){var AX_XHR_NAMES = ["Microsoft.XMLHTTP", "Msxml2.XMLHTTP"],
i = 0;if(!window.XMLHttpRequest) {
for(i=AX_XHR_NAMES.length; i >=0; i=i-1) {
try {
xmlHttp = ActiveXObject(AX_XHR_NAMES[i]);
} catch(e) {}
}
} else {
xmlHttp = new XMLHttpRequest();
}})();function updatePage() {
if(xmlHttp.readyState==4) {
if(xmlHttp.status==200) { alert(xmlHttp.responseText);
var response = xmlHttp.responseText;
//test1.innerHTML=response;
document.getElementById("test1").innerHTML="<span>" + response + "<\/span>";
}
}
}
function callServer()
{
var url = "PageName.aspx";
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8');
xmlHttp.onreadystatechange=updatePage;
xmlHttp.send("Id=" + escape("zx"));//post提交时参数要放在这里
};
</script>
<input type="button" value="test" onclick="callServer();"/>
<span style="padding:0 2px 0 2px; font-size:10pt; font-weight:bolder;" id="test1" class="xiahuaxian"> </span>