Microsoft.XMLHTTP基本用法

例子,在asp程式定义,调用,在另外一个页面实现功能!
定义,调用(一般写成一个触发事件onblur)
function progPM_onblur(){
if (frmAddPJ.prog_PM.value != ''){
var URL = 'chkPM.asp?progPM=' + frmAddPJ.prog_PM.value;
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST",URL,false);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset:big5")
xmlHttp.send();
//var returnValue = eval(xmlHttp.responseBody);  //用responseBody只能取到單個,數字或者字母
//var returnValue = eval(xmlHttp.responseText); //用responseBody只能取到一個或多個數字
//var returnValue = xmlHttp.responseXML.xml;     //取出xml代碼
//alert(returnValue);  不是很清楚的類型,最后测试,不要用eval,否则出错
//alert(returnValue.toString().length());
var returnValue = xmlHttp.responseText;
if (returnValue != 'Y') {
 alert('該用戶不存在或沒有權限');
 frmAddPJ.prog_PM.value = '';
 frmAddPJ.prog_PM.focus();
 }
 xmlHttp = null;
 return;
 }
}


实现功能的页面,
<!-- #include file = "header.asp" -->
<%
olecodepage = session.CodePage
session.CodePage = 65001
on error resume next
progPM  = request.QueryString("progPM")
if chkR(progPM,"M") = 0 then  '是否具有專案經理的權限 /调用了一个函数,其实就如一般的页面一样动作即可
response.Write "N"
else
response.Write "Y"
end if
session.CodePage =  olecodepage
%>


posted on 2005-01-13 21:18  郁狂  阅读(4146)  评论(1)    收藏  举报