按照示例弄了下例子:
<s:url id="ajaxTest" value="/jsonPlugin.do" />
<s:a theme="ajax" href="%{ajaxTest}" indicator="indicator" targets="userHolder"
notifyTopics="retrieveUser">go to json ajax sample</s:a>
<script type="text/javascript">
dojo.addOnLoad(function() {
dojo.event.topic.subscribe('retrieveUser', this, function(data, type, e){
alert(type);
alert(data);
if(type == 'load') {
showUser(data);
} else if(type == 'error') {
alert('Can not retrieve the user');
}
});
});
function showUser(strUser) {
alert('strUser');
var oUser = eval('(' + strUser + ')');
var userHolder = document.getElementById('userHolder');
var sUser = ('<b><i>Comments: </i></b><hr/>');
for(i = 0; i < oUser.users.length; i++) {
sUser += ('<p><b>#' + (i + 1) + ' </b>' + oUser.users[i].cardNo + '</p>');
}
userHolder.innerHTML = sUser;
}
</script>
<div id="userHolder">go to json ajax sample data will be here</div>
结果alert(type); 时是before 而不是load,错误信息:XMLHttpTransport error callback failed: TypeError: node has no properties
求明示。。。