Loading data via jquery ajax for datagrid?

I have this piece of code (but not complete, but ignore the final 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}); 

Code for GetJson.jsp:

<%@ 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>

I have a get method of request j. And the url I am passing returns me a Json array string. URL output ::

[{"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"}] 

Now I want this output for my ie data grid, I want var myVar to get this value, and then it will be passed to dojo.data.ItemFileWriteStore. I can not do it. Please help? Thank you

0
source share
2 answers

$.get() AJAX $.ajax() - , , A AJAX . AJAX, , $.get().

( :

function gotoa() {
    var store;

    var h = $.get("http://localhost:8080/2_8_2012/jsp/GetJson.jsp", function(result) {
        var myVar = result;
        var storedata={
            identifier:"ID",
            label:"name",
            items: myVar
        };

        store = new dojo.data.ItemFileWriteStore({data: storedata}); 
            // do whatever with store here, if necessary
    });
}
0

script :

<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:

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

<%=temp1 %>

gotoa() ajax

0

All Articles