0

my html:

<html>
     <head>
          <script src="dojo/dojo.js"></script>
          <script src="app/my.js"></script>
          <script>
                handleResult(<%server response data%>);
          </script>
     </head>
     <body>
          <div id="data"></div>
     </body>
</html>

my js:

require(["dojo/_base/Array"],function(Array){
     handleResult = function(data){
         Array.forEach(data,function(item,index){
               //Process the data
         });
     }
});

When the page loads call handleResult, I get an error:

Uncaught ReferenceError: test is not defined 

But I can get this function in firebug window.handleResult please help me .thank.

1
  • Works for me: fiddle. Commented Nov 29, 2013 at 9:29

2 Answers 2

1

Do NOT use onclick, please.

require(["dojo/on", "dojo/dom"],function(dom) {
     var button = dom.byId("demo"));
     on(button, "click", function(evnt) {
         console.log(evnt);
     })
});
Sign up to request clarification or add additional context in comments.

1 Comment

And the "test" function used in onClick is not in the right context and it is thus not found. By using the on event handling of dojo, the function actually is found, so this does solve you problem. Please use this.
0

The require function is asynchronous. You cannot define a global variable from inside a require callback and then try to immediately access it. You should also never define globals to begin with, this is one of the basic tenets of AMD. Your application architecture is wrong and will never work. You need to use an AJAX call to request the “server response data” once the application is loaded on the client, and not try to do what you are doing.

1 Comment

NO. DO NOT use a synchronous Ajax call, EVER. It completely hangs your UI. Fix your code to work properly with asynchronous operations.

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.