js|web
<!--
//使用方法,直接调用sendRequest(url, Method, HttpMethod, params)方法
//参数说明:url--访问地址;Method--调用的服务方法;HttpMethod--传递方法,默认post;params--需要传递的参数或信息;
//多参数使用&连接,post方法经过测试;
//注意!
//成功传输回响函数为xmlResponse(),请自行在此js引用之前添加,否则无效,回响内容为req.responseText,默认为同步。
function getXMLRequester( ){ //此函数是建立XMLHTTP组件的,可能ie低版本无法使用,请参阅msdn;
var xmlhttp_request = false;
try{
if( window.ActiveXObject ){
for( var i = 5; i; i-- ){
try{
if( i == 2 ){
xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" );
}else{
xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
xmlhttp_request.setRequestHeader("Content-Type", "text/xml;charset=utf-8");
}
break;}
catch(e){
xmlhttp_request = false;
}
}
}else if( window.XMLHttpRequest ){
xmlhttp_request = new XMLHttpRequest();
if (xmlhttp_request.overrideMimeType) {
xmlhttp_request.overrideMimeType('text/xml');
}
}
}catch(e){
xmlhttp_request = false;
alert("对不起您的浏览器版本太低,请更新后使用。");
}
return xmlhttp_request ;
}
var req;
function sendRequest(url, Method, HttpMethod, params) {
url += "/" + Method;
if (!HttpMethod){
HttpMethod = "POST";
}
req = getXMLRequester(); //建立组件
if (req) {
req.onreadystatechange = processReqChange;//调用进程监视函数
req.open(HttpMethod, url, true);
req.setRequestHeader("Host", "202.115.138.116");
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.setRequestHeader("Content-Length",params.length);
req.send(params); //发送数据参数
}
}
function processReqChange() {
// 监视数据传递。
if (req.readyState == 4) {
if (req.status == 200) {
xmlResponse(); // connect OK 执行输出函数out()
} else { //抛出错误
alert("无法正常连接服务器,错误:\n" +
req.statusText+":"+req.status);
}
}
}
-->
<HTML>
<HEAD>
<META http-equiv='Content-Type' content='text/html;charset=gb2312'>
<Meta name='Gemeratpr' content='网络程序员伴侣(Lshdic)2005'>
<TITLE></TITLE>
<SCRIPT language='Jscript'>
<!--
function xmlResponse() {
message.value = req.responseText;
}
-->
</SCRIPT>
<SCRIPT language=jscript src='file:///C:/Documents and Settings/losingrose/桌面/js/HttpRequest.js' ></SCRIPT>
</HEAD>
<BODY>
<textarea id='send' value='' rows='2' ></textarea>
<INPUT type='button' value='sdfsdf' onclick='sendRequest("http://202.115.138.116/ChatWebService/Service.asmx","dataset","POST","a="+send.value+"&b=2&c=3453");' />
<textarea id='message' value='' rows='8' ></textarea>
</BODY>
</HTML>