最近在摆弄jeasyui,这玩意儿用着方便,称手,但太方便了,就少了一点灵活。
在用jeasyui中DataGrid请求WebService(asmx文件)时,莫名的出现没数据,具体表现为:
本地开发调试,能正常请求到服务器数据;
发布到IIS上后,客户端电脑访问,就请求不到数据了;
在服务器上作本地访问,又能请求到数据;(是不是有点意思了。)
用jQuery的ajax请求WebService(asmx文件)时,一直正常。
开发环境:Windows XP 下的VS2008
js框架:jquery-1.7.2.min.js
jquery.easyui.min.js
用Firebug看-------------因 URL 意外地以“/xxxxxxxxxx”结束,请求格式无法识别。
谷老师说:
要在webservice的 <system.web> 节点下加入:
<system.web> <webServices>
<protocols>
<add name= "HttpPost" />
<add name= "HttpGet" />
</protocols>
</webServices>
.....
</system.web>
webservice节点紧跟在<system.web>节点之后
把二者请求和返回过程用Firebug看一下,得到的东西对比一下,
Easyui Datagrid请求:
Headers:
ResponseHeaders:
//手动在服务器端设定Context.Response.ContentType = "application/json; charset=utf-8";
//如果不设定,则没有下面的Content-Type
Server ASP.NET Development Server/9.0.0.0
Content-Type application/json; charset=utf-8
RequestHeaders:
Content-Type application/x-www-form-urlencoded; charset=UTF-8 //application/x-www-form-urlencoded(使用HTTP的POST方法提交的表单)
Accept application/json,text/javascript,*/*; q=0.01
X-Requested-With XMLHttpRequest
Post:
Parameters: application/x-www-form-urlencoded
invs_id 1041 //这是参数,
JSON: //JSON没有数据,
Source:
invs_id=1041 //注意格式
-----------------------------------------------------------------------------------------------------
jQuery ajax请求:
Headers:
ResponseHeaders:
Server Microsoft-IIS/6.0
ResponseHeaders: Content-Type application/json; charset=utf-8
Accept application/json,*/*; q=0.01
X-Requested-With XMLHttpRequest
Post:
//Parameters参数
JSON //JSON有数据
invsId 1041 //这是参数
Source
{invsId:1041} //注意格式
Easyui的请求(实际底层是jQuery的ajax请求),如果不设定Content-Type,默认会加上application/x-www-form-urlencoded;
出现:因 URL 意外地以“/xxxxxxxxxx”结束,请求格式无法识别。原因肯定是Content-Type为application/x-www-form-urlencoded引起的;
但为什么本机访问可以请求到数据,客户端电脑访问服务器就不行了呢?(。。。。。。)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。