0

我创建了一个 WCF REST 服务,它只返回这样的 JSON {"Id":10,"Name":"Peter"} 并使用 Chrome 我可以看到此响应,但使用以下 HTML5,状态为 0。可以有人告诉我我做错了什么吗?谢谢

<!DOCTYPE html>
<html>
    <head>
        <title>Company Name</title>
        <link rel="shortcut icon" href="favicon.ico"/>
        <script>
        window.onload = function()
        {
            var url = "http://localhost:8732/DataService/data/10";
            request = new XMLHttpRequest();
            request.onreadystatechange = function()
            {
                if(request.readyState == 4)
                {
                    if(request.status == 404)
                    {
                        document.getElementById("content").innerHTML = "No page found";
                    }
                    if(request.status == 2 || request.status == 200)
                    {
                        document.getElementById("content").innerHTML = "<br /><br /><br />Response: " + request.responseText;
                    }
                    else
                    {
                        document.getElementById("content").innerHTML = "Status: " + request.status +" ReadyState: " + request.readyState    + "<br /> " + request.responseText;
                    }
                }
            }
            request.open("GET", url, true);
            request.send(null);
        }
        </script>
    </head>

    <body>
        <div id="container" style="width:100%;">
            <div id="header" style="position:absolute; height:100px;width:inherit;">
                <img src="Dialog.bmp" alt="Missing" />
            </div>          
    <!--        <div id="menu" style="background-color:#33CCFF; height:200px;width:100px;float:left;">
            <b>Menu</b><br>
            HTML<br>
            CSS<br>
            JavaScript</div> margin:0 auto; height:100%;width:100%;-->
            <br /><br /><br /><br />

            <div id="content" style="background-color:#333333; height:500px;width:inherit;float:left; color:white">Content goes here</div>          
            <div id="footer" style="background-color:#00A8FF;clear:both;text-align:center;color:white;font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif">Copyright © CompanyName</div>        
        </div>
    </body>
</html>
4

1 回答 1

0

好像我在做跨域请求并且 IE+9 允许它,但不是 Chrome。

我现在已将 JSON WCF 请求移至 Apache 转发的 PHP cURL。

于 2013-12-07T06:05:08.723 回答