JQuery JSONP ajax调用WCF会触发错误和回调函数

时间:2014-12-07 16:44:23

标签: jquery ajax wcf jsonp

这真的很奇怪,我已经尝试找到解决方案但是还没有成功,即使在阅读了一堆页面并尝试了大量示例之后,即使这可能是一个重复的问题。 / p>



<!DOCTYPE html>

<html>
<head>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

<script type="text/javascript">
    function JsonPCallBack(result) {
        console.log('success');
        console.log(result);
         $(result).each(function (index, value) {  
                $("#TableID").append("<tr><td>" + value.SymbolName + "</td><td>" + value.BidPrice + "</td><td>" + value.AskPrice + "</td></tr>");  
            });  
    };

    $(document).ready(function () {

        $('#btnRefresh').on('click', function (event) {
            $.ajax({
                type: "GET",
                dataType: "jsonp",
                url: "http://wcfhostwebsite.dev/Service.svc/GetLatestSymbolData?method=JsonPCallBack",
                error: function (error) {
                    if (error.status != "200") {
                        console.log("error");
                        console.log(error);
                    }
                }
            });
        });


    });
</script> 


</head>
<body>
<button id="btnRefresh">Refresh</button>
<form id="form1" runat="server">  
        <table id="TableID" cellpadding="0" cellspacing="0" border="1"  width="400px" >  
            <tr>  
                <td style="background-color: green; color:white">SymbolName</td>  
                <td style="background-color: green; color:white">BidPrice</td>  
                <td style="background-color: green; color:white">AskPrice</td>  
            </tr>  
        </table>  
    </form>  
 
</body>
</html>
&#13;
&#13;
&#13;

即使我从WCF服务得到适当的响应(见下文)并且触发了回调函数,它仍会触发错误。

JsonPCallBack( {"AskPrice":125.77778,"BidPrice":123.44557,"SymbolDate":"\/Date(1415142000000+0100)\/","SymbolName":"EUR"} );

我已添加了一种解决方法来检查状态,但我对此并不满意。

请指教?

0 个答案:

没有答案