2

I am trying to load a table with data by initializing a Javascript variable with a string in JSON format. If I declare:

<script type="text/javascript">
var data = new String("{totalCount: '1', identifier: 'EntityID', items: [{'EntityID':'1','Country':'United States','Region':'','State':'California','County':'Santa Clara','City':'San Jose','ZipCode':'95134'}]}");
var d3 = eval('(' + data + ')');
<span dojoType="dojo.data.ItemFileWriteStore" jsId="dataStore" data=d3></span>
</script>

then my table will correctly load the row.

I have tried initializing a Java string before my script and then passing that object into a Javascript variable like so:

<%
String d = "{totalCount: '1', identifier: 'EntityID', items: [{'EntityID':'1','Country':'United States','Region':'','State':'California','County':'Santa Clara','City':'San Jose','ZipCode':'95134'}]}";
%>

<script type="text/javascript">
var data = new String(<%=d%>);
// var data = new String(d) // tried this as well
var d3 = eval('(' + data + ')');
<span dojoType="dojo.data.ItemFileWriteStore" jsId="dataStore" data=d3></span>
</script>

My table does not recognize this and is unable to load the row when I attempt to pass it this way. How can I properly pass a Java string to Javascript so that my table will be able to load the data?

2
  • Do you get an error message? Commented Jul 30, 2013 at 18:02
  • Yes, sorry, I should have posted the console log. The error is: error in getting data for table: table. Error dojo.data.ItemFileWriteStore: No JSON source data was provided as either URL or a nested Javascript object. Commented Jul 30, 2013 at 18:06

1 Answer 1

1

Try with quotes around.

var data = new String("<%= d %>");
Sign up to request clarification or add additional context in comments.

1 Comment

@raphnguyen Yep, "finicky".. that's how they've always been.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.