📄 httprequest.js
字号:
<!--
//使用方法,直接调用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=gb2312");
}
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, false);
req.setRequestHeader("Host", "202.115.138.248");
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
if(params != null)
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);
}
}
}
-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -