IE crashes on eval(json)

115 views
Skip to first unread message

Zoran Jeremic

unread,
Jun 25, 2010, 2:52:52 AM6/25/10
to jsTree
Hi,

I've recently switched to jstree 1.0. I downloaded the recent one from
SVN, and I found out that I have a problem with interpreting it in IE.
I'm using JSON data that I got from Web service. I found that the code
crashes at the evaluation of json data on eval() function.

var myJstreeData=eval(json);

It works perfectly in FF.
Do you have any idea about this?

Zoran

Ivan Bozhanov

unread,
Jun 25, 2010, 3:03:39 AM6/25/10
to jst...@googlegroups.com
Why do you eval?

Cheers,
Ivan

> --
> You received this message because you are subscribed to the Google Groups "jsTree" group.
> To post to this group, send email to jst...@googlegroups.com.
> To unsubscribe from this group, send email to jstree+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jstree?hl=en.
>
>

Zoran Jeremic

unread,
Jun 25, 2010, 4:04:57 AM6/25/10
to jsTree
Here is the JSON string I sent from Web Service
[{ data : 'byTasks', children : [ { data : 'Only child 2', state :
'closed' } ], state : 'open' },"+
"{ data : 'Ajax node 2' }]

If I just pass it to jstree without evaluation, the whole this string
is in one root node as a title, and in the older version it couldn't
initialize jstree at all. eval() of the json object I receive from the
Web service solved the problem, and it used to work in FF and IE.
However, now it doesn't.

Do you have any suggestion what I can use instead of this?

Zoran

On Jun 25, 9:03 am, Ivan Bozhanov <ivan.bozha...@gmail.com> wrote:
> Why do you eval?
>
> Cheers,
> Ivan
>

vakata

unread,
Jun 25, 2010, 4:06:43 AM6/25/10
to jsTree
Either use the latest commit of jstree, or add "dataType" : "json", to
the AJAX config :)

Cheers,
Ivan

Zoran Jeremic

unread,
Jun 25, 2010, 6:34:25 AM6/25/10
to jsTree
Hi Ivan,

I did as you said and still have no results. I added jquery.jstree.js
from svn v.181 and "datatype":"json", and it's the same. If I use
eval() function, FF works and IE (I added try..catch blok) fires
object Error. If I don't use eval(), then both FF and IE create just a
root node with the whole json string as its title.

Here is my configuration.

$("#basic_html").jstree({
"dataType": "json",
"json_data" : {
"data" : leftTreeIniData
},
"types":{
"valid_children":["root"],
"types":{
"root" : {
"draggable" :false,
"valid_children" : [ "folder","competence" ],
"icon" : {
"image" : "images/monitor.png"
}
},
"folder" : {
"valid_children" : [ "competence" ]
},
"competence" : {
"valid_children" : ["competence"],
"draggable" : true,
"max_children" : 0,
"max_depth" :0,
"icon" : {
"image" : "images/file.png"
}
}
}
},
"plugins" : [ "themes",
"json_data","types","ui","dnd","crrm" ]
});

Zoran

Ivan Bozhanov

unread,
Jun 25, 2010, 7:12:58 AM6/25/10
to jst...@googlegroups.com
Sorry,

I did not know you used static data - how do you get that data? Add
"dataType" "json" to the ajax call where you load the data, not as you
did above.

Please paste where leftTreeIniData comes from (where do you set the
variable) and I will tell you what to do - it is generally bad
practice to eval, when you have other options. The issue is not jstree
related :)

Cheers,
Ivan

Zoran Jeremic

unread,
Jun 25, 2010, 8:03:27 AM6/25/10
to jsTree
Hi Ivan,

I have Tuscany Web Service defined in

@Remotable
public interface AvailableCompetencesService {
String getAvailableCompetences(String sortingCriteria);
}

Method getAvailableCompetences returns json in string format. This is
the peace of that code:

StringBuilder competences = new StringBuilder();
...
String byTasksTest="[{ data : 'byTasks', children : [ { data : 'Only
child 2', state : 'closed' } ], state : 'open' },"+
"{ data : 'Ajax node 2' }]";
String byColegues="[ { 'data' : 'Karin Spors', 'children' :
[ { 'data' : 'Strak - Manager' } ], 'state' : 'open' }, { 'data' :
'Jessica Bluhm' } ]";
if (sortingCriteria.equals("0")){
competences.append(byRoles);
}else if (sortingCriteria.equals("1")){
competences.append(byTasks);
}else
competences.append(byColegues);
return competences.toString();

Then I use dojo to access this service with:

function getAvailableCompetences(sortCriteria,callbackFunction){
dojo.addOnLoad(function() {
dojo.require("dojo.parser");
dojo.require("dojo.rpc.JsonService");
var smd=new dojo.rpc.JsonService("CreateLearningGoalsService?smd");

smd.getAvailableCompetences(sortCriteria).addCallback(callbackFunction);
});
}

This is a callback I pass to above function as parameter:

function leftTreeContentCallBack(result) {
try{
var leftTreeData=eval(result);
}catch(e){
alert('Error happened during evaluation of the results'+e);
}
addLeftTree(leftTreeData);
}

Finally, addLeftTree function create jsTree. I posted it in previous
comment.

Zoran

On Jun 25, 1:12 pm, Ivan Bozhanov <ivan.bozha...@gmail.com> wrote:
> Sorry,
>
> I did not know you used static data - how do you get that data? Add
> "dataType" "json" to the ajax call where you load the data, not as you
> did above.
>
> Please paste where leftTreeIniData comes from (where do you set the
> variable) and I will tell you what to do - it is generally bad
> practice to eval, when you have other options. The issue is not jstree
> related :)
>
> Cheers,
> Ivan
>

Ivan Bozhanov

unread,
Jun 25, 2010, 8:11:14 AM6/25/10
to jst...@googlegroups.com
I see, well I am not familiar with Dojo, so I cannot really help you
here - all I can recommend is this:
http://www.json.org/js.html

Especially this part: var myObject = eval('(' + myJSONtext + ')'); //
notice the '(' + and + ')'
It should work :)

Cheers,
Ivan

Zoran Jeremic

unread,
Jun 25, 2010, 2:06:36 PM6/25/10
to jsTree
Hi Ivan,

I found that the problem was caused by mistakes in json string. There
were some , between }}. Somehow, this is ignored in FF, but not in
IE.

However I still have some problems:

1) I got error "Invalid property id" both in FF and IE for this json
string:

[{data : 'A node', attr:
{id:'phtml_1',rel:'root',class:'star'},children : [ { data: {title:
'XV5'}, attr: { id:'phtml_2' , rel:'competence', class:'star' }},
{ data: {title:'XV6'},attr:
{id:'phtml_3',rel:'competence',class:'star' } }],{data : {title: 'Long
format demo'}, attr : {id : 'test' } } }]

Is there something wrong with this string?


2) IE doesn't recognize node types identified by rel attribute. It
works well in FF, and root and competence in the above example has
different icons. In IE, each node has a "folder" icon instead.

Zoran



On Jun 25, 2:11 pm, Ivan Bozhanov <ivan.bozha...@gmail.com> wrote:
> I see, well I am not familiar with Dojo, so I cannot really help you
> here - all I can recommend is this:http://www.json.org/js.html
>
> Especially this part: var myObject = eval('(' + myJSONtext + ')'); //
> notice the '(' + and + ')'
> It should work :)
>
> Cheers,
> Ivan
>
Message has been deleted
Message has been deleted

Ivan Bozhanov

unread,
Jun 25, 2010, 3:19:23 PM6/25/10
to jstree
Hi,

make sure you have quotes around class (it is a reserved keyword) so
do it like this:

"class" : "value"

which is also better JSON :)

As for type icons - IE6 does not support them, all higher version do,
I do not intend to fix that :)

Cheers,
Ivan

On Fri, Jun 25, 2010 at 21:20, Zoran Jeremic <jere...@yahoo.com> wrote:
>
> Hi Ivan,
>

> I found that the problem was caused by some sufficient "," I added
> between parentheses }}
>
> However, I still have some problems, like:
>
> 1)"invalid property id", both in FF and IE, in this example.


>
> [{data : 'A node', attr:
> {id:'phtml_1',rel:'root',class:'star'},children : [ { data: {title:
> 'XV5'}, attr: { id:'phtml_2' , rel:'competence', class:'star' }},
> { data: {title:'XV6'},attr:
> {id:'phtml_3',rel:'competence',class:'star' } }],{data : {title: 'Long
> format demo'}, attr : {id : 'test' } } }]
>

> Is there something wrong with this json string?
>
> 2)IE doesn't interpret node types identified with 'rel' attribute. It
> uses default "folder" icon for each node type.
>
> Zoran


>
>
> On Jun 25, 2:11 pm, Ivan Bozhanov <ivan.bozha...@gmail.com> wrote:
>> I see, well I am not familiar with Dojo, so I cannot really help you
>> here - all I can recommend is this:http://www.json.org/js.html
>>
>> Especially this part: var myObject = eval('(' + myJSONtext + ')'); //
>> notice the '(' + and + ')'
>> It should work :)
>>
>> Cheers,
>> Ivan
>>

Zoran Jeremic

unread,
Jun 25, 2010, 4:17:05 PM6/25/10
to jsTree
Hi,

> do it like this:
>
> "class" : "value"

I already tried this.
This is the last code I have tried:

[{'data' : 'A node', 'attr':
{'id':'phtml_1','rel':'root','class':'star'},'children' : [ { 'data':
{'title': 'XV5'}, 'attr': { 'id':'phtml_2' , 'rel':'competence',
'class':'star' }},{ 'data': {'title':'XV6'},'attr':
{'id':'phtml_3','rel':'competence','class':'star' } }],{'data' :
{'title': 'Long format demo'}, 'attr' : {'id' : 'test' } } }]

> As for type icons - IE6 does not support them, all higher version do,
> I do not intend to fix that :)

I don't use IE6, but IE8, and with Developer tool I have switch to IE7
compatibility mode, and I have this problem.

Zoran
> > For more options,- Hide quoted text -
>
> - Show quoted text -...
>
> read more »

vakata

unread,
Jun 26, 2010, 4:39:15 PM6/26/10
to jsTree
As for the error - you have missed a closing }, just before the long
format demo, after the closing ]

As for the compatibility view - I just tested - the types demo works,
so it should be an error in your config. Paste it and I may be able to
help you.

Cheers,
Ivan
> > >> >> >> > > > You received this message because you are subscribed to the- Скриване на цитирания текст -
>
> - Показване на цитирания текст -...
>
> четете още»
Reply all
Reply to author
Forward
0 new messages