• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

js调用WebService_jquery

jquery 搞代码 7年前 (2018-06-12) 219次浏览 已收录 0个评论

<!–
    //使用方法,直接调用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′ style=’width:100;’ ></textarea>
<INPUT type=’button’ value=’sdfsdf’ onclick=’sendRequest(“http://202.115.138.116/ChatWebService/Service.asmx&#8221;,”dataset”,”POST”,”a=”+send.value+”&b=2&c=3453″);’ />
<textarea id=’message’ value=” rows=’8′ style=’width:500;’ ></textarea>
</BODY>
</HTML>

 

欢迎大家阅读《js调用WebService_jquery,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:js调用WebService_jquery
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址