Posted by Rakward on June 8, 2010 at 9:43am
I'm currently working on a module to load some views-results in a window on the page when click/hovering them.
I'd like to know whats the standard/best way of loading drupal functions in an ajax request to I can for example do a node_load and some other stuff in a custom .php file?
Curently I'm just getting the entore page with ajax (written something within a hook_menu to get what I want, so I have my php code) and then cut off the html I don't need.
Obviously a very bad way of coding, especially for an image heavy site.
So, best way to load drupal's functions in ajax?
Comments
1) Register a path using
1) Register a path using hook_menu().
2) Use the path you just registered as the callback URL for your AJAX call
3) In the callback function for the path you registered in step 1, do whatever PHP you need to do.
4) Don't return anything from the callback function - instead print/echo it. Then run die() at the end of your function. Any data printed/echoed will be sent back to your AJAX call.
5) Take the data and do whatever it is you need to do.
Full-time freelancer, always looking for work.
jaypan.com (my portfolio)
I had already found something
I had already found something else(checking page.tpl.php for the path, echo the normal template for normal page, echo only content on a certain path) but this seems alot better.
I'll try testing this out sometime, thanks.
------------------------
Born to lose, live to win.
- Junior Drupaller