<script language="javascript">
var xmlHttpRequest = null;
function selectionChanged() {
// IE only.
xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
string = "objstr=1";
//發送資料
xmlHttpRequest.open("POST", "A.aspx", false);//提交到A.aspx
xmlHttpRequest.setrequestheader("content-length", string.length);
xmlHttpRequest.setrequestheader("content-type", "application/x-www-form-urlencoded");
xmlHttpRequest.send(string);
xmlHttpRequest.onreadystatechange=onReadyStateChange;
}
function onReadyStateChange() {
if (xmlHttpRequest.readyState == 4) {
if (xmlHttpRequest.status == 200) {
var w= xmlHttpRequest.responseText;
}
}
}
</script>
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/plain";
string objstr= Request.Form["objstr"].ToString();
Response.Write("Hello World"+objstr);
Response.End();
}
另外,AJAX是不支援跨域提交的,這應該是瀏覽器的許可權的