Jose
Jose

Reputation: 617

Parsing Error/Syntax

I am attempting to use the onload event to call my json objects from a server & put them inside title panes. At the moment I'm only trying to take one object out of the DB. However, I keep getting this error on the console:

  dojo/parser::parse() error SyntaxError {} 

Its highlighted the parser.js file line 411.

Here's a snippet:

<div data-dojo-props="title: 'Json is here', open:false" data-dojo-type="dijit/TitlePane" id="tab"  onload= " dojo.require('dijit/TitlePane');

    dojo.xhrGet({
    url: 'http://171.23.34:3000/page.json',
    handleAs: 'json',
    timeout : 2000,

    load: function(data){

    dojo.byId('tab').innerHTML = data[0].Name;
     dojo.parser.parse('tab');

},
error: function(error){
    dojo.byId('tab').innerHTML = "An unexpected error occurred:" + error;
}
}



});"
preload="true" selected="true" >

</div>

Could someone please shed some light if I'm doing this completely wrong?

Upvotes: 0

Views: 1551

Answers (1)

Craig Swing
Craig Swing

Reputation: 8162

You have defined an html attribute onLoad="..." and within the onload function you have the following:

 dojo.byId('tab').innerHTML = "An unexpected error occurred:" + error;

The first quote in this line closes the onLoad attribute in HTML and the rest of the function is parsed as html and fails.

Try putting your onload method in a declarative script tag.

http://dojotoolkit.org/reference-guide/1.8/dojo/parser.html#declarative-scripting-arguments

EDIT

In addition to changing to single quotes, you also have an extra close brace in your function.

dojo.xhrGet({
    url: 'http://171.23.34:3000/page.json',
    handleAs: 'json',
    timeout : 2000,

    load: function(data){
        dojo.byId('tab').innerHTML = data[0].Name;
        dojo.parser.parse('tab');

    },
    error: function(error){
        dojo.byId('tab').innerHTML = 'An unexpected error occurred:' + error;
    }
    //} <-- extra brace
});

Upvotes: 1

Related Questions