2011-03-26 2 views
0

크로스 도메인 요청 WCF 데이터 서비스가 json 데이터로 응답하지만 자바 스크립트 오류가 발생합니다 ';' 브라우저의. 이 오류로 인해 $ .ajax 성공 처리기가 실행되지 않습니다. 이 문제의 원인을 파악할 수 없습니다.jquery wcf 데이터 서비스 jsonp - 자바 스크립트 오류 ';'예상

피들러

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> 

답변

0

당신이 크로스 도메인 JSONP 요청을 사용하는 경우, 귀하의 응답은 여기처럼 콜백 함수에 싸여해야합니다 http://search.twitter.com/search.json?callback=foo&q=terefere - 상기 볼 요청에 매개 변수 callback이 있으면 twitter 서비스는이 매개 변수를 찾아서 응답을 값 뒤에 호출 된 함수로 래핑합니다.

+0

네가 맞다. 와일드 카드 맞아. URL에서 $ callback 매개 변수를 잊어 버렸습니다. http : //../myservice.svc/surveys? $ callback = callback & $ format = json – dm80

+0

유용한 링크 - http://stephenwalther.com/blog/archive/2010/04/01/netflix-jquery-jsonp-and -odata.aspx – dm80