Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By HXn on
I have a db table with items I need to remove.
On the /user page, I have a list of said items corresponding to the current user.
The user clicks a delete icon and the item disappears.
The script.js file:
$(function() {
// remove item from display
$('.gift-list .registry-item .remove').click(function(e) {
$(this).parent().fadeOut('slow');
// remove item from db
// ajax code goes here
});
});
I have a function in mymodule.module that will include the removal code.
How do I call my function via Ajax, so the page does not reload for the user? How can I make it degrade gracefully?
Thanks
Comments
You need a menu item (type =
You need a menu item (type = MENU_CALLBACK) in your modules hook_menu() that has as the page callback the function in mymodule.module. Function should generally print something (I generally use the json format) even if its only a success indicator. So your function might end in something like
or if you need to return more than success, something like
Thanks
Worked like a charm.
For those who may come across this post, here is the code I have:
mymodule.module
script.js
Thanks for the solution
Thanks for the solution. It just work nicely.