惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
Last Week in AI
Last Week in AI
月光博客
月光博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
博客园 - 叶小钗
NISL@THU
NISL@THU
C
Check Point Blog
K
Kaspersky official blog
N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
T
Threatpost
GbyAI
GbyAI
L
LINUX DO - 热门话题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Scott Helme
Scott Helme
P
Privacy International News Feed
The Register - Security
The Register - Security
G
GRAHAM CLULEY
Recorded Future
Recorded Future
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
DataBreaches.Net
J
Java Code Geeks
AWS News Blog
AWS News Blog
Help Net Security
Help Net Security
Engineering at Meta
Engineering at Meta
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News

博客园 - 朱胜

exeCommand 阻止浏览器事件传递 Ext js Grouping 展开和折叠方法 JS获取上传文件的绝对路径,兼容IE和FF - 朱胜 - 博客园 asp.net2.0中异步调用WebService - 朱胜 - 博客园 ASP.Net的正则表达式(RegularExpression) Extjs简介(二) Extjs框架简介(一) ASP.NET 压缩和解压缩 - 朱胜 - 博客园 ASP.NET 恢复备份Sql server - 朱胜 WPF学习2:布局(上) WPF学习笔记1 WPF生命周期和参数配置 WPF编程笔记 0:WPF概况(上部分) JavaScript判断文件大小 - 朱胜 - 博客园 clientHeight,offsetHeight和scrollHeight区别 CSS HACK(ie6-ie7-fox 兼容) 页面禁止后退的方法 upLoad控件设置禁止输入的方法 - 朱胜 - 博客园 [ASP.NET] 实现Label自动换行 - 朱胜 - 博客园
js调用web服务范例 - 朱胜 - 博客园
朱胜 · 2008-12-04 · via 博客园 - 朱胜

1.Web服务

        [WebMethod]
        public string webServiceTest(string userID)
        {
            return userID;
        }

2. 调用方法

RequestByGet("http://www.xxx.com/webService.asmx/webServiceTest?userID=leochu2008",null);

3. 脚本函数

function RequestByGet(url,data)
        {
            var xmlhttp;
            try
            {
                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(E)
                {
                    xmlhttp=null;
                }
            }
            if(!xmlhttp&&typeof(XMLHttpRequest)!=="undefined")
            {
                xmlhttp=new XMLHttpRequest();
            }
            xmlhttp.Open("GET",url, false);
            xmlhttp.Send(data);
            var result = xmlhttp.status;
            if(result==200)
            {
                document.write(xmlhttp.responseText);
            }
            xmlhttp = null;
        }
       
        function RequestByPost(url,value)
        {
            var xmlhttp;
            try{
                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(E)
                {
                   xmlhttp=null;
                }
            }
            if(!xmlhttp&&typeof(XMLHttpRequest)!=="undefined")
            {
                xmlhttp=new XMLHttpRequest();
            }
            xmlhttp.Open("POST",url, false);
            xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=gb2312");
            xmlhttp.Send(data);
            document.write( xmlhttp.responseText);
        }

如果调用不成功或提示“因 URL 意外地以xxx结束,请求格式无法识别”,要在webservice的 <system.web> 节点下加入
        <webServices>
          <protocols>
              <add   name= "HttpPost "   />
              <add   name= "HttpGet "   />
          </protocols>
</webServices>