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

推荐订阅源

量子位
G
GRAHAM CLULEY
S
Security @ Cisco Blogs
T
The Exploit Database - CXSecurity.com
I
Intezer
The Last Watchdog
The Last Watchdog
Project Zero
Project Zero
Simon Willison's Weblog
Simon Willison's Weblog
S
Secure Thoughts
Webroot Blog
Webroot Blog
F
Full Disclosure
L
Lohrmann on Cybersecurity
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
V
Visual Studio Blog
H
Heimdal Security Blog
NISL@THU
NISL@THU
L
LINUX DO - 最新话题
Hugging Face - Blog
Hugging Face - Blog
TaoSecurity Blog
TaoSecurity Blog
S
Securelist
博客园 - 聂微东
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
MyScale Blog
MyScale Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
T
Tailwind CSS Blog
C
Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Stack Overflow Blog
Stack Overflow Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
Google Developers Blog
C
CERT Recently Published Vulnerability Notes
aimingoo的专栏
aimingoo的专栏
D
DataBreaches.Net
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
SecWiki News
SecWiki News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
AWS News Blog
AWS News Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Engineering at Meta
Engineering at Meta
PCI Perspectives
PCI Perspectives
V
V2EX
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

博客园 - -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":"恭喜!认证成功!"}

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