JSONP跨域WCF服务响应失败 [英] JSONP CROSS- DOMAIN WCF Service Response Fail

查看:65
本文介绍了JSONP跨域WCF服务响应失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是WCF服务代码:

This is the WCF Service code:

[OperationContract]
        [WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
        public String GreetJson()
        {
            Greeting g = new Greeting();
            g.Message = "Hello World!";
            Console.WriteLine("call received");
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return serializer.Serialize(g); ;
        }



和客户要求:



and the client request:

$("#test").click(function(){
$.getJSON("http://192.168.10.183:8001/GreetJson",function(data)
            {
                alert("test=" + data);
            });
});
...
<img src="data/images/menu/highscore.png" alt="Highscore" id="test" />



如果我们在浏览器中使用http://192.168.10.183:8001/GreetJson,则会得到:
"{\" Message \:\" Hello World!\}"

我们的问题是,当我们执行getJSON请求时,我们没有从服务器收到任何响应.

Console.WriteLine(已接电话"); //该消息出现在控制台中,但在浏览器上没有警报框.
知道为什么吗?



if we use http://192.168.10.183:8001/GreetJson in a browser we get:
"{\"Message\":\"Hello World!\"}"

Our problem is that we don''t receive any response from the server when we do getJSON request.

Console.WriteLine("call received"); //the message appears in the console but on the browser there is no alert box.
Any idea why?

推荐答案

(" ).click(function(){
("#test").click(function(){


.getJSON(" http://192.168.10.183:8001/GreetJson",功能(数据) { alert(" + data); }); }); ... < img =" data/images/menu/highscore.png" alt =" id / >
.getJSON("http://192.168.10.183:8001/GreetJson",function(data) { alert("test=" + data); }); }); ... <img src="data/images/menu/highscore.png" alt="Highscore" id="test" />



如果我们在浏览器中使用http://192.168.10.183:8001/GreetJson,则会得到:
"{\" Message \:\" Hello World!\}"

我们的问题是,当我们执行getJSON请求时,我们没有从服务器收到任何响应.

Console.WriteLine(已接电话"); //该消息出现在控制台中,但在浏览器上没有警报框.
知道为什么吗?



if we use http://192.168.10.183:8001/GreetJson in a browser we get:
"{\"Message\":\"Hello World!\"}"

Our problem is that we don''t receive any response from the server when we do getJSON request.

Console.WriteLine("call received"); //the message appears in the console but on the browser there is no alert box.
Any idea why?


这篇关于JSONP跨域WCF服务响应失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆