通过Jquery ajax为datagrid加载数据? [英] Loading data through Jquery ajax for datagrid?

查看:304
本文介绍了通过Jquery ajax为datagrid加载数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码片段(不完整,忽略结束脚本标签)::

I have this code snippet(not complete though, ignore the ending script tag) ::

<script type="text/javascript">
function gotoa(){
    var h = $.get("http://localhost:8080/2_8_2012/jsp/GetJson.jsp", function(result) {

    });
    alert(result);


var myVar= h;
var storedata={
            identifier:"ID",
            label:"name",
            items: myVar
    };

var store = new dojo.data.ItemFileWriteStore({data: storedata}); 

GetJson.jsp的代码是::

The code for GetJson.jsp is ::

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="MyPackage.PopulateTextbox" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<%

String temp1;
PopulateTextbox obj = new PopulateTextbox();
temp1 = obj.method();
%>

<%=temp1 %>

</head>
<body>


</body>
</html>

我有一个j查询获取方法。而我传递的URL返回给我一个Json数组字符串。输出URL ::

I have a j query get method . And the URL i am passing in it returns me an Json array string. Output of URL ::

[{"ID":1,"Names":"Shantanu","Email":"shantanu.tomar@gmail.com"},{"ID":2,"Names":"Mayur","Email":"mayur.sharma@gmail.com"},{"ID":3,"Names":"Rohit"},{"ID":4,"Names":"Jasdeep"},{"ID":5,"Names":"Rakesh","Email":"rakesh.shukla@gmail.com"},{"ID":6,"Names":"Divyanshu"},{"ID":8,"Names":"hello"},{"ID":9,"Names":"fine"},{"ID":10,"Names":"shivani"}] 

现在我想要这个输出对于我的数据网格,即我想要var myVar应该得到这个值,然后它将被传递到dojo.data.ItemFileWriteStore。我不能这样做请帮忙 ?谢谢。

Now i want this output for my Data grid i.e i want that var myVar should get this value and then it will be passed on to dojo.data.ItemFileWriteStore. I am unable to do so . Please help ? Thanks.

推荐答案

修改您的脚本标签,如下所示:

modify your script tag like this:

<script type="text/javascript">
function gotoa(){
    $.get("http://localhost:8080/2_8_2012/jsp/GetJson.jsp", function(result) {
        var storedata={
            identifier:"ID",
            label:"name",
            items: result
             };

            var store = new dojo.data.ItemFileWriteStore({data: storedata});
    });

}
</script>

GetJson.jsp的代码是:

The code for GetJson.jsp is :

<%@page contentType="application/json" %>
<%@page import="MyPackage.PopulateTextbox" %>
<%
String temp1;
PopulateTextbox obj = new PopulateTextbox();
temp1 = obj.method();
%>

<%=temp1 %>

现在调用 gotoa()
它将初始化ajax调用并在回调函数

Now call gotoa() it will initialize the ajax call and get the response in callback function

这篇关于通过Jquery ajax为datagrid加载数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆