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

推荐订阅源

D
Docker
Microsoft Azure Blog
Microsoft Azure Blog
云风的 BLOG
云风的 BLOG
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LangChain Blog
P
Privacy & Cybersecurity Law Blog
Hugging Face - Blog
Hugging Face - Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
A
Arctic Wolf
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
The GitHub Blog
The GitHub Blog
P
Privacy International News Feed
WordPress大学
WordPress大学
U
Unit 42
S
Securelist
T
The Exploit Database - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
Latest news
Latest news
Hacker News: Ask HN
Hacker News: Ask HN
小众软件
小众软件
Know Your Adversary
Know Your Adversary
The Cloudflare Blog
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
Security Latest
Security Latest
Google DeepMind News
Google DeepMind News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - Franky
Y
Y Combinator Blog
博客园 - 叶小钗
Security Archives - TechRepublic
Security Archives - TechRepublic
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
S
Secure Thoughts
T
Threat Research - Cisco Blogs
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
M
MIT News - Artificial intelligence

博客园 - -Enchant

Linux上搭建Asp.net MVC3环境(CentOS + Nginx + Mono) 《单例模式》你需要注意的问题 系统框架整理 Extjs prompt 显示密码框 Python网页抓取、模拟登录 单点登录(SSO)的一点思考 WCF初探 关于抓取百度搜索内容 iPhone开发环境搭建(备忘) SMTP/POP3命令简介(转) C/S模式下 简单的定时任务功能 Asp.net MVC2学习笔记索引 Oracle 调优 Oracle常见错误 @OutputCache指令参数 关于ACL权限控制【ASP.NET MVC2】 c#递归生成XML ASP.NET MVC2 Ajax返回JSON 引用类型的对象复制(浅复制和深复制)
Jquery以JSON方式调用WebService
-Enchant · 2010-09-20 · via 博客园 - -Enchant

<webServices>
<protocols>
<add name="HttpPost" />
<add name="HttpGet" />
</protocols>
</webServices>

今天测试了用jquery调用webservice,调用是没问题的,可是默认的webservice是返回给我们xml格式的,

这样对对于我们后续的操作很不方便,于是查找了 使用 json格式传送,始终没能够成功,后来参考了下 京东的 调用,终于知道原因所在了。。呵呵

Jquery以JSON方式调用WebService 

在webservice中需要添加如下节点(在 system.web节点下)

1、首先根据webservice类里面的提示修改

// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]

2、然后在webservice中需要返回json数据的方法加上如下属性

     

[ScriptMethod(ResponseFormat=ResponseFormat.Json)]

   ScriptMethod在 using System.Web.Script.Services 命名空间下,这里还可以设置是否使用 get方式来调用 UseHttpGet=true

3、最后写jquery调用脚本

function doJSON() {
$.ajax({
url:
"http://localhost:11143/MyApplicationService.asmx/TestMethod",
data: {ssokey:
"'" + ssokey + "'"},
dataType:
"JSON",
contentType:
"application/json; charset=utf-8",
success:
function (data) {
alert(data);
}
});
}

   这里有几个地方需要注意的,否则不成功

   a、data: {ssokey:"'" + ssokey + "'"}   -- 这里我传递了参数,需要这种写法,一定要写成 json对象,否则失败(这个地方折腾了好久。。。)

   b、dataType: "JSON" ---- 这里告诉 jquery 以 json格式传递

   c、ontentType: "application/json; charset=utf-8" --- 设置head 里面使用  json传递

上面三点都注意到以后就应该可以成功的调用并返回 json对象了

返回的json 对象是被保证在 d 对象中的,大家 alert一下就知道了,类似这种  

  {"d":"恭喜!认证成功!"}

上面就是今天“研究”的结果。。。