Reputation: 57
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.
Upvotes: 0
Views: 107
Reputation: 18826
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.
Upvotes: 0
Reputation: 4131
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);
})
});
Upvotes: 1