jQuery无法从WCF REST服务获取响应

编程入门 行业动态 更新时间:2024-10-27 18:24:15
本文介绍了jQuery无法从WCF REST服务获取响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经开发了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服务获取响应

本文发布于:2023-10-12 02:57:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jQuery   WCF   REST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!