请帮忙。
我发
数据
xmlhttprequest
到ASP。
为什么我的内容重复?
如果我不写
document.getElementById('qz').innerHTML = xmlhttp.responseText;
,则不会显示任何内容。
<body><div id="container"><button id="the-button" >Click me</button>
<form id="Form1" runat = "server">
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click2" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<% string rd = Request["x"]; string rd1 = Request["y"];Response.Write("res"+rd+" "+rd1);%>
</form> </div> <div id="qz"></div></body>
<script type="text/javascript">
function get_var() {
var x = "12";
var y = "14"
var params = 'x=' + encodeURIComponent(x) + '&y=' + encodeURIComponent(y);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "pr_peremennya.aspx", true);
xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('qz').innerHTML = xmlhttp.responseText;
}
};
xmlhttp.send(params);
}
document.addEventListener("DOMContentLoaded", function () {
document.getElementById("the-button").addEventListener("click", get_var);
});
</script>