我正在使用ngTable動態顯示json文件中的數據並更新表。但是,我的代碼不起作用。 下面是一些代碼片段:
$http.jsonp("http://127.0.0.1:3000/sampledate.json")
.success(function(data) {
//console.log(data);
$scope.user = data; });
下面是HTML表(ngTable)的樣品:
<div ng-controller="tableController">
<table ng-table="tableParams" show-filter="true" class="table table-striped" infinite-scroll-distance="3">
<tr ng-repeat="user in $data">
<td data-title="'Id'" sortable="'id'">
{{user.id}}
</td>
<td data-title="'File Name'" sortable="'file_name'" filter="{ 'file_name': 'text' }">
{{user.file_name}}
</td>
<td data-title="'Type'" sortable="'type'" filter="{ 'type': 'text' }">
{{user.type}}
</td>
<td data-title="'File Date'" sortable="'file_date'" filter="{ 'file_date': 'text' }">
{{user.file_date}}
</td>
<td data-title="'Hour'" sortable="'hour'" " filter="{ hour: 'number'}">
{{user.hour}}
</td>
<td data-title="'Bucket'" sortable="'bucket'">
{{user.bucket}}
</td> </tr></table></div>
人能給我如何解決這一些想法? 或者給我一些關於完成我的任務的想法。
我的問題不是網絡問題。見下文。
請求URL:http://127.0.0.1:3000/sampledate.json 請求方法:GET 狀態代碼:200 OK(從高速緩存) 遠程地址:127.0.0.1:3000
不能在靜態json文件上使用'jsonp'請求。同樣,對於'$ http.jsonp',您必須使用文檔中概述的回調字符串,不作任何變化。你還沒有提供任何回調參數。由於請求是API你控制我懷疑你想要jsonp無論如何。這是一個跨端口/跨域請求嗎? – charlietfl
是的。之前它是一個跨域問題。現在,因爲我使用$ http.jsonp,它不應該再是這個問題了。我使用了$ http.get,那時出現了跨域問題。 –
在服務器上實現CORS。或者使用jsonp,您需要一個服務器腳本來從文件中提取內容並將其包裝在jsonp回調函數中,並且您需要將'callback'參數添加到url – charlietfl