WCF REST 服务和 jQuery
我设法创建了一些 REST 服务,并且可以通过浏览器完全访问它们,例如 http://localhost:port /uri/template/value - 它返回值。但是,我在通过 jQuery 访问它时遇到问题。我之前创建了可以通过 $.ajax() 调用访问的 MVC 控制器操作,但这一个让我难住了。我可能错过了一些大的或微小但至关重要的东西。 VS2010 解决方案文件已在此处压缩,而不是在此处粘贴代码: http://savitarbernese.com/WCF_Prototypes.zip< /a>.
任何帮助将不胜感激。
谢谢, 丹妮.
I managed to create some REST services and they're perfectly accessible through the browser, e.g. http://localhost:port/uri/template/value - and it returns the value. However, I am having problems accessing it through jQuery. I have previously created MVC controller actions that I could access through $.ajax() calls, but this one has me stumped. I'm probably missing either something big, or tiny but crucial. Instead of pasting code here the VS2010 solution file has been zipped up here: http://savitarbernese.com/WCF_Prototypes.zip.
Any assistance would be greatly appreciated.
Thanks,
Dany.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的网页是从与 Web 服务不同的端口提供服务的,那么这就是跨域调用,并且它将不起作用。您可能需要在同一端口上托管服务,或者考虑在它们上支持 Jsonp。
If your web pages are being served from a different port than the web services, then that's a cross domain call, and it won't work. You may need to either host the services on the same port, or else look into supporting Jsonp on them.
你有两个问题。
锚元素上的点击事件甚至没有触发,我将其更改为按钮,并且它像应有的那样触发。
您发送请求的 uri 错误。您有:
http://localhost:1414/crypto .svc/sha512/createhash/?inputText=This+is+some+text
应该是:
http://localhost:1414/crypto.svc/sha512/createhash/This +是+一些+文字
You have two problems.
the click event on the anchor element isn't even firing, I changed that to a button and it fired like it should have.
The uri you are sending your request to is wrong. You have:
http://localhost:1414/crypto.svc/sha512/createhash/?inputText=This+is+some+text
It should be:
http://localhost:1414/crypto.svc/sha512/createhash/This+is+some+text