Dojo Toolkit的新功能,我能够成功地在页面加载时加载xhrGet,但是当我选择一行DataGrid时,我需要加载xhrGet。有没有办法这样做?
<!doctype html>
<html>
<head>
<script type="text/javascript>
dojo.connect(btn, "onclick", function() {
/************************/
/* xhr - AJAX functions */
/************************/
dojo.ready(function(){
var targetNode = dojo.byId("xhr-container");
var xhrArgs = {
url: "info-to-get.html",
handleAs: "text",
load: function(data){
targetNode.innerHTML = data;
},
error: function(error){
targetNode.innerHTML = "You messed up, dummy!: " + error;
}
}
var deferred = dojo.xhrGet(xhrArgs);
});
});
</script>
</head>
<body>
<button type="button" id="btn">TEST</button>
<br>
<br>
<div id="xhr-container"></div>
</body>
</html>
xhrGet在页面加载时单独工作,在尝试通过按钮调用时没有骰子。
答案 0 :(得分:1)
这将点击html domNode的点击以触发一个函数,您可以在其中放置xhr代码。
dojo.connect(someDomNode, 'onclick', function() {
//xhr code here
});
如果它是一个小部件,比如dijit.form.Button
你可以写
dojo.connect(someWidget, 'onClick', function() {
//xhr code here
});
- 编辑----------------------
根据您发布的代码,我希望以下内容有效:
dojo.ready(function(){
var targetNode = dojo.byId("xhr-container");
var fnDoXHR = function() {
var xhrArgs = {
url: "info-to-get.html",
handleAs: "text",
load: function(data){
targetNode.innerHTML = data;
},
error: function(error){
targetNode.innerHTML = "You messed up, dummy!: " + error;
}
};
var deferred = dojo.xhrGet(xhrArgs);
};
dojo.connect(dojo.byId('btn'), 'onclick', fnDoXHR);
});