我想显示一组数据,我通过使用 dojo.xhrget() 方法对服务器进行异步调用来检索这些数据。我正在通过 URL 检索数据,并且我希望每次用户在内容窗格中单击时,都会在网格中显示一组新值,而无需刷新整个页面。问题是数据没有显示在网格中。我通过 xhrget() 错误方法收到错误。
我的脚本的代码是::
<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>
现在,这里 alert(data) 和http://localhost:8080/2_8_2012/jsp/GetJson.jsp的输出是相同的,即 ::
[{"ID":1,"Names":"Shantanu","Email":"shantanu.tomar@gmail.com"},{"ID":2,"Names":"Mayur","Email":"mayur.sharma@gmail.com"},{"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">
我没有得到什么问题。你能帮我弄清楚为什么我会收到错误警报吗?谢谢。