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

推荐订阅源

A
Arctic Wolf
博客园 - 聂微东
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
小众软件
小众软件
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
L
LangChain Blog
A
About on SuperTechFans
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
T
The Blog of Author Tim Ferriss
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
Know Your Adversary
Know Your Adversary
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Palo Alto Networks Blog
Scott Helme
Scott Helme
S
Secure Thoughts
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
H
Heimdal Security Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
G
Google Developers Blog
博客园 - Franky
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
Kaspersky official blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tor Project blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tenable Blog
Google Online Security Blog
Google Online Security Blog
PCI Perspectives
PCI Perspectives

博客园 - 朱胜

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>