我想顯示一組數據,我使用dojo.xhrget()方法通過對服務器的異步調用來檢索數據。我通過URL檢索數據,我希望每次用戶單擊內容窗格時,都會在網格中顯示一組新的值,而無需刷新整個頁面。問題是數據沒有在網格中顯示。我正在通過xhrget()錯誤方法收到錯誤。使用dojo.xhrget()方法在Dojogrid中顯示數據
我的腳本的代碼::
<script>
function populateGrid(){
dojo.xhrGet({
url: "http://localhost:8080/2_8_2012/jsp/GetJson.jsp",
load: fillGrid,
error:handleError,
preventCache:true
});
}
function fillGrid(data, ioArgs)
{
alert(data);
var newData = {
identifier: "ID",
items: data
};
var dataStore = new dojo.data.ItemFileReadStore({data: newData, id:"dataStoreId"});
var gridStructure =[[
{ field: "ID",
name: "ID_Emp",
width: "20%",
classes:"firstName"
},
{
field: "Names",
name: "Name",
width: "20%",
classes: "firstName"
},
{ field: "Email",
name: "Mail",
width: "20%",
classes:"firstName"
}
]
];
var grid = dijit.byId("grid.DataGrid");
grid.setStore(dataStore);
grid.startup();
}
function handleError() {
alert("An error occurred while invoking the service.");
}
</script>
現在,這裏警報(數據)和http://localhost:8080/2_8_2012/jsp/GetJson.jsp的輸出是相同的,即::
[{"ID":1,"Names":"Shantanu","Email":"[email protected]"},{"ID":2,"Names":"Mayur","Email":"[email protected]"},{"ID":26,"Names":"Rohit"}]
我xhr.get功能工作在數據檢索方面很好。即當我更新數據庫中的值。我確實得到了具有該更新值的警報(數據)輸出,而無需再次刷新整個頁面。但數據不顯示在數據網格中。
我收到警報
An error occurred while invoking the service.
爲http://localhost:8080/2_8_2012/jsp/GetJson.jsp的代碼::
<%@ page language="java" contentType="application/json; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="MyPackage.PopulateTextbox" %>
<%
String temp1;
PopulateTextbox obj = new PopulateTextbox();
temp1 = obj.method();
%>
<%=temp1 %>
的標記代碼::
<div id="grid.DataGrid" data-dojo-type="dojox.grid.DataGrid" title="Simple Grid" data-dojo-props= "autoWidth:true, structure: gridStructure" style="width:900px; height:200px;"></div>
<div id="contentpaneid" dojoType="dijit.layout.ContentPane" title="Pending Activities" style="background-image: url('http://localhost:8080/2_8_2012/images/17.png');" onclick="populateGrid">
我沒有得到什麼問題。你能幫我解答爲什麼我會收到錯誤提示。謝謝。
我試圖顯示什麼是錯誤..和我GT這個:: 404網格是未定義的。 – 2012-03-19 10:53:33
我從你最近的一個問題中得到了這個問題,從你把它鏈接到哪裏。在閱讀完您的問題後,我想,您正試圖在數據網格實際檢索之前將數據綁定到您的數據網格。所以,在不知不覺中你將你的網格綁定到null/undefined對象,這可能會產生你看到的錯誤。不確定,但你只需確認一次,如果是這樣的話。 – MrClan 2012-03-19 12:42:11
謝謝Pratik .. :) – 2012-03-20 06:25:30