前臺
<input type="text" name="name" id="name1" />
<div id="Creadit">
這里顯示資料
</div>
<input type="button" value="https://bbs.csdn.net/topics/更新DIV" onclick="sendRequest()" />
<script type="text/javascript">
var xhr = new window.XMLHttpRequest();
function sendRequest() {
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
document.getElementById("Creadit").innerHTML = xhr.responseText;
}
}
};
var name = document.getElementById("name1").value;
xhr.open("POST", "Handler1.ashx", true);
xhr.setRequestHeader("ContentType", "application/x-www-form-urlencoded");
xhr.send("username" + name);
}
</script>
后臺: string name = context.Request["name"];
context.Response.Write("Hello World"+name);
name 為NULL 但是xhr.send是有資料的 如果加個編碼就有管用了 用JQuery是可以的 但是原生的不行,但是加上編碼就又可以
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/270018.html
標籤:Ajax
上一篇:求解 g={};什么意思
