开发者

jquery wcf data service jsonp - javascript error Expected ';'

Cross domain request the WCF data service responds with json data but I get a javascript error Expected ';' on the browser. This error prevents the $.ajax success handler from firing. Can't figure ou开发者_JS百科t what's causing this.

fiddler

HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 368
Content-Type: application/json;charset=utf-8
Server: Microsoft-IIS/7.5
DataServiceVersion: 2.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 26 Mar 2011 00:19:20 GMT

{
"d" : {
"results": [
{
"__metadata": {
"uri": "http://subdomain.domain.com/services/Service1.svc/Surveys(410)", "type": "SurveyModel.Survey"
}, "OBJECTID": 410, "ID_Reviewer": "007", "ID_Reviewee": "007", "Rating": 9, "Question_A_Text": "test 1", "Question_B_Text": "test 2", "DateSubmitted": "\/Date(1301034211000)\/"
}
]
}
}

.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {    
            $.ajax({
                url: "http://subdomain.domain.com/services/Service1.svc/Surveys/?$format=json",
                dataType: "jsonp",
                success: function (data) {
                    alert("success");
                }
            });    
        });
    </script>
</head>
<body>
</body>
</html>


if you're using cross-domain jsonp request, your response should be wrapped in a callback function, like here: http://search.twitter.com/search.json?callback=foo&q=terefere - look at the callback parameter in the request, twitter service looks for this parameter and wraps response into function called after it's value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜