我想从其他网站调用 Web 服务并使用 Ajax 调用在 html 页面中获得响应。
数据应该是 Web 服务的响应。我已经尝试了很多,但我没有得到任何解决方案。我也穿过浏览器,使用 ajax 请求调用 web 服务时出现问题。
我的网络服务代码:
[ServiceContract]
public interface IService
{
[WebInvoke(Method = "GET",RequestFormat=WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
//[WebGet]
[OperationContract]
string GetData(string inputString);
}
It is implemented as:
public string GetData(string inputString)
{
return "myData";
}
Javascript code (From my other website):
<script type="text/javascript">
function click_btn() {
$.ajax({
type: "GET",
url: "http://192.168.15.213/MyService.svc/GetData/inputString=e",
contentType: "application/json",
success: function (jsonData) {
alert('Data: ' + jsonData);
`enter code here` },
Error: function (e) {
alert('err: ' + e);
}
});
return false;
}
</script>
404 method not allowed
当我从另一个网站调用 web 服务时出现错误。