我已经开发了WCF rest服务并将其部署在可以通过浏览器访问的链接上,因为它的动作是"GET".
I have developed WCF rest service and deployed it on a link that can be accessed via the browser because its action is "GET".
我想使用jQuery获得该数据.我尽力使用jQuery获得WCf响应 但徒劳无功.我也尝试了$ .Ajax和'jsonp',但是没有运气.有人可以帮我吗?
I want to get that data using jQuery. I tried my best to get WCf get response using jQuery but in vain. I also tried $.Ajax with 'jsonp' with no luck. Can any one help me?
网址为: www.lonestarus/AndroidApp/AndroidLocation.svc/RestService/getLatestLocation
您可以通过将URL粘贴到浏览器中来检查该URL响应.
You can check that url response by pasting url in browser.
推荐答案您需要在响应标题中将 Access-Control-Allow-Origin 设置为[*]值.
You need to set Access-Control-Allow-Origin to value [*] in your response header.
此博客详细介绍了如何在WCF REST服务中完成该操作
this blog gives the more details how it can be done in WCF REST service
如果要在Web API中执行此操作,则可以添加
if you were to do this in Web API you could have just added
Response.Headers.Add("Access-Control-Allow-Origin", "*")使用小提琴拨打服务
$(function() { $.ajax({ url: "www.lonestarus/AndroidApp/AndroidLocation.svc/RestService/getLatestLocation", datatype: 'json', type : 'get', success: function(data) { debugger; var obj = data; } }); });我得到了错误
XMLHttpRequest无法加载 www.lonestarus/AndroidApp/AndroidLocation.svc/RestService/getLatestLocation . 不允许 fiddle.jshell 访问控制允许来源.
XMLHttpRequest cannot load www.lonestarus/AndroidApp/AndroidLocation.svc/RestService/getLatestLocation. Origin fiddle.jshell is not allowed by Access-Control-Allow-Origin.
更多推荐
jQuery无法从WCF REST服务获取响应
发布评论