Secure practices for ajax/jquery links
Web 2.0 has ajax capability which is today very fast adopted by major portion of web. Ajax technology is made child’s play by jquery libraries. Regular hyperlinks can be converted into ajax links just by giving id/class name to it and then attaching a event listener to that. While initial jquery developers tends to get excited with this feature and start utilizing this feature site wide not knowing the fallacy with the approach.
If you see ajax using sites like orkut and many others then you will find that no websites are creating a direct hyperlink with href information in them. Rather doing mouse over them shows void(0). This is important it is a better alternative than using “#” in the hyper link which redirects browser url by appending “#” to it and everything then becomes unclickable.
there are two approaches here set the href property of a anchor to void(0) and for geenrating proper event keep them inside onclick event or bind the class/id using jquery event listener.
<a href=”javascript:void(0)” onclick=”doSomeThing()”>click me</a>
or
<a href=”javascript:void(0)” class=”delete”>click me</a>
This is a good practice and advantages are that the information inside your links are hidden and no one can do “copy link URL” and past it on the browser window. Which makes ajax calls useless.