最近在摆弄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> 节点下加入:
<webServices>?
<protocols>?
<add name= "HttpPost " />?
<add name= "HttpGet " />?
</protocols>?
</webServices>? ? ? ? ? ? ? ??
把二者请求和返回过程用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引起的;
但为什么本机访问可以请求到数据,客户端电脑访问服务器就不行了呢?(。。。。。。)