我正在使用Visual Studio 2012.我創建了一個名爲ODataService的空Web應用程序項目,並添加了一個SQL Server Compact 4.0本地數據庫,然後添加了一個ADO.NET實體數據模型本地數據庫。現在添加了一個使用實體模型的WCF數據服務。所有這些都在一個單獨的項目下,即ODataService。創建這個之後,我可以很容易地從瀏覽器查詢數據:在這裏我有ODataService項目相同的解決方案使用WCF數據服務消耗OData時出現JSON錯誤
i.e. http://localhost:52964/EmployeeService.svc/Employees()?$filter=ID gt 3
現在我已經添加了一個MVC3應用。在MVC3項目,我已經編碼在Index.cshtml以下,以使用OData使用jQuery:
<script type="text/javascript">
$(document).ready(function() {
var qry = "http://localhost:52964/EmployeeService.svc/Employees?$filter=ID gt 3&$callback=callback&$format=json";
var qry2 = "http://odata.netflix.com/v2/Catalog/Titles?$filter=ReleaseYear gt 2012&AverageRating gt 4&$callback=callback&$format=json";
$('#loadData').click(function() {
$('#loadingText').text('loading data...');
$.ajax({
dataType: "jsonp",
url: qry,
jsonpCallback: "callback",
success: callback,
error: function (jqXHR, textStatus, errorThrown) {
debugger;
}
});
});
function callback(result) {
debugger;
}
});
當我使用我的qry2代碼運行良好,但使用QRY調試器時打在錯誤部分並顯示「parsererror」 - 「回調未被調用」。
任何形式的幫助表示讚賞。
是Web服務包裝的JSON對象'回調(/ * json * /)'?你有沒有驗證它在jsonlint.com中生成的json? – charlietfl