qiang
3 Jan 2008, 11:46 AM
hi,
i am wondering what is the best way to keep javascript out of html in extjs. for example i have html like this:
<a href="/app/profile/123/vote/yes">yes</a>
i want to rewrite it to send ajax request but don't want to mix bunch of onClick into the html. also the ajax request url is readily available in the html page and i don't want to somehow hard code the url in javascript. i am hoping event handler can help me on this. so in the end i would like to do:
<a href="/app/profile/123/vote/yes" id="vote_yes">yes</a> <div id="vote_msg"></div>
then in my ext I do:
Ext.onReady(function(){
Ext.get('vote_yes').on('click', function(){
# send ajax request using the href url
# then update vote_msg field
});
});
this way, i hope that the link is still clickable even if user has javascript disabled.
I don't know javascript much to to disable the href so that user wont be taken to another page when they clicking on it.
what's your opinion?
i am wondering what is the best way to keep javascript out of html in extjs. for example i have html like this:
<a href="/app/profile/123/vote/yes">yes</a>
i want to rewrite it to send ajax request but don't want to mix bunch of onClick into the html. also the ajax request url is readily available in the html page and i don't want to somehow hard code the url in javascript. i am hoping event handler can help me on this. so in the end i would like to do:
<a href="/app/profile/123/vote/yes" id="vote_yes">yes</a> <div id="vote_msg"></div>
then in my ext I do:
Ext.onReady(function(){
Ext.get('vote_yes').on('click', function(){
# send ajax request using the href url
# then update vote_msg field
});
});
this way, i hope that the link is still clickable even if user has javascript disabled.
I don't know javascript much to to disable the href so that user wont be taken to another page when they clicking on it.
what's your opinion?