<script type="text/javascript">
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) {
alert(xmlHttp.responseText);
}
};
xmlhttp.open("get", "proSort.aspx?strID=as", false);
xmlhttp.send();
}
</script>
string ItemsList = Request.Form.Get("strID");
string ItemsList1 = Request.QueryString["strID"];
string ItemsList1 = Request.QueryString["strID"];
你用的是get请求,上面的代码就可以取值
xmlhttp.open("get", "proSort.aspx?strID=as", false);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
;
}
};
xmlHTTP.setRequestHeader("Content-Type", "text/xml");
xmlHTTP.send();
注意代码顺序
也可用jquery的ajax函数
楼主的代码我测试了,后台可以获取到值。
<script type="text/javascript">
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) {
alert(xmlhttp.responseText);//测试 这里弹出 <h1>as</h1>
}
};
xmlhttp.open("get", "default.aspx?strID=as", false);
xmlhttp.send();
}
default.aspx:
<input type="button" value="click" onclick="javascript:loadXMLDoc()" />
protected void Page_Load(object sender, EventArgs e)
{
string id = Request["strID"];
if (!string.IsNullOrEmpty(id))
{
Response.Write("<h1>" + id + "</h1>");
Response.End();
}
else
{
Response.Write("<h1>Null or Empty</h1>");
}
}