Ajax best practise for custom links I was reading up on AJAX requests in Drupal 7 at http://codekarate.com/blog/drupal-7-javascript-ajax-framework-example-link

Where the AJAX framework is explained in detail, when used on custom links and potentially other HTML elements.

Now it got me wondering,

In a more "custom" point of view, I have created some (regular) hook_menu() implementations in the past, (without any /ajax or /nojs stuff) that would just return json data.

So, basically I implemented links in my custom module that would get called via a custom jQuery file (via $.post or $.get), via a click() event or something like this, that in turn fired the hook_menu() mentioned above.

This would then return some json data after processing the request, this returned data would get fetched by my jQuery script, and the DOM would be updated with the data that was returned by the ajax call (json, ...).

Now I am just wondering on the pro's and con's of both ways of doing things.

It figures that the first one is more "the Drupal way", and the second one is much more custom...

Since I never had any issue with using the second way of things, I am very curious to hear what you all have to say on this matter.

Thanks in advance.

Best

Guardian
yes - you can always do custom stuff, but miss all the features of the framework.

some pros:


works with javascript disabled (/nojs)
you can use the form-api 1:1 (more or less ..), so forms are reusable
you can use predefined commands (like replace or alert) and create your own
it's all ready for jquery ui
you can write your own and overwrite behaviors (and it's settings) from other modules
you can use drupal translations
with ctools it gets even more powerful, like modals, AJAX Responder etc.
there are a lot of modules you can use (qucktabs, modal forms, masonry .. you name it ..)
you can have all JS libraries managed
for JSON with website content you can use views datasource module


the contra is you need to be willing to learn and adapt :D