2015-02-11 47 views
0

我正在使用JQuery EasyUI的datagrid是一个非常基本的实现。无法使用JavaScript方法加载JQuery EasyUI数据网格

如果我使用内联的方式来加载数据所有的罚款,并有数据显示(注意JSON API的工作,我已经启用了CORS的服务器上,以便这不是问题):

<table class="easyui-datagrid" 
     data-options="url:'https://www.driverlive.co.uk/rest/api/PushMessage/GetPushDriverMessagesList?DeviceId=a99f8a977696bfb9&DateFrom=2014-10-27T00:00:00&DateTo=2015-11-11T00:00:00',method:'get',singleSelect:true,fit:true,fitColumns:true"> 
    <thead> 
     <tr> 
      <th data-options="field:'PushDriverMessageDBID'" width="80">Item ID</th> 
      <th data-options="field:'PushDriverMessageGuid'" width="100">PushDriverMessageGuid</th> 
      <th data-options="field:'AppKey',align:'right'" width="80">AppKey</th> 
      <th data-options="field:'PushNotificationMessage',align:'right'" width="300">PushNotificationMessage</th> 
      <th data-options="field:'Sender'" width="150">Sender</th> 
      <th data-options="field:'MessageDated',align:'center'" width="50">MessageDated</th> 
     </tr> 
    </thead> 
</table> 

如果我尝试加载数据网格的JavaScript方式,我没有得到任何数据,但我不明白为什么?

// Dispatching DataGrid 
var JSONDispatchingURL = "https://www.driverlive.co.uk/rest/api/PushMessage/GetPushDriverMessagesList?DeviceId=a99f8a977696bfb9&DateFrom=2014-10-27T00:00:00&DateTo=2015-11-11T00:00:00"; 
     $('#DGDispatching').datagrid({ 
      url: JSONDispatchingURL, 
      columns: [[ 
       { field: 'PushDriverMessageDBID', title: 'PushDriverMessageDBID', width: 100 }, 
       { field: 'PushDriverMessageGuid', title: 'PushDriverMessageGuid', width: 100 }, 
       { field: 'AppKey', title: 'AppKey', width: 100 }, 
       { field: 'PushNotificationMessage', title: 'PushNotificationMessage', width: 100 }, 
       { field: 'Sender', title: 'Sender', width: 100 }, 
       { field: 'MessageDated', title: 'MessageDated', width: 100} 
      ]] 
     }); 

我与这里的jsfiddle相同的结果:http://jsfiddle.net/b6fxs2v2/1/

我已经在这里跟着指示:http://www.jeasyui.com/documentation/datagrid.php,所以我有点失落......

回答

0

确定。我解雇了Fiddler,结果表明JQuery EasyUI使用POST而不是GET来调用服务。因此,REST API响应了405.响应具体是{“Message”:“请求的资源不支持http方法'POST'。”}

我发现了类似的this SO post,然后修改了我的代码,如下所示。然后这工作!

var JSONDispatchingURL = "https://www.driverlive.co.uk/rest/api/PushMessage/GetPushDriverMessagesList?DeviceId=a99f8a977696bfb9&DateFrom=2014-10-27T00:00:00&DateTo=2015-11-11T00:00:00"; 
     $('#DGDispatching').datagrid({ 
      url: JSONDispatchingURL, 
      method: 'get', 
      columns: [[ 
       { field: 'PushDriverMessageDBID', title: 'PushDriverMessageDBID', width: 100 }, 
       { field: 'PushDriverMessageGuid', title: 'PushDriverMessageGuid', width: 100 }, 
       { field: 'AppKey', title: 'AppKey', width: 100 }, 
       { field: 'PushNotificationMessage', title: 'PushNotificationMessage', width: 100 }, 
       { field: 'Sender', title: 'Sender', width: 100 }, 
       { field: 'MessageDated', title: 'MessageDated', width: 100 } 
      ]] 
     });