Send info via ajax to update database

CalvinHobbs - July 1, 2009 - 19:08

First this is my first module so I'm sure that there's things that I am doing that are wrong, but I have everything working except the database interaction.

First my javascript snippets:

    function xdpDrop() {
        $('li',$xdp).droppable({
                accept: '.xdg > li',
                activeClass: 'ui-state-highlight',
                hoverClass: 'drophover',
                tolerance:'pointer',
                drop: function(ev, ui) {
                        var xBookmark = ui.draggable.attr('class').split(' ').slice(0,1);
                        var xFolder = $(this).text();
                        var xUpdateInfo = new Array(xBookmark, xFolder);
                       
                        updateBookmark(xUpdateInfo);
                       
                        deleteBookmark(ui.draggable);
                }
        });
    }

    function updateBookmark(xUpdateInfo) {
     
        $.get('/bookmarks/update/bookmarks/', xUpdateInfo, updateBookmarkDetails);
    return false;       
    }
   
    var updateBookmarkDetails = function (data) {
        var result = Drupal.parseJson(data);
    }

Ironically this doesn't error out at all in Firebug, but the database doesn't get updated at all

Here's the php snippet from the module

/**
* Implementation of hook_menu().
*/
function flag_categories_menu() {
  $items = array();
 
  $items['bookmarks/get/bookmarks'] = array(
    'page callback' => 'flag_categories_get_bookmarks_ajax',
    'type' => MENU_CALLBACK,
    'access arguments' => array('access content'),
  );
  $items['bookmarks/update/bookmarks'] = array (
    'page callback' => 'flag_categories_update_bookmarks_ajax',
    'type' => MENU_CALLBACK,
    'access arguments' => array('access content'),
  );
  $items['bookmarks/delete/bookmarks'] = array (
    'page callback' => 'flag_categories_delete_bookmarks_ajax',
    'type' => MENU_CALLBACK,
    'access arguments' => array('access content'),
  );
  
  return $items;
}


function flag_categories_update_bookmarks_ajax($cid) {
 
  $account = $GLOBALS['user'];
  $content_id = $cid->xBookmark;
  $cat = 'TEST'; //$cid->xFolder;
 
 
    db_query("UPDATE {flag_content} SET cat = '%s' WHERE AND content_id = %d AND uid = %d",
    $cat, $content_id, $account->uid);
 
}

Right now I am just working on the updates so the other functions haven't been put in.

Any help would be great.

Thanks

Only skimmed you code, but,

briansea - July 6, 2009 - 02:51

Only skimmed you code, but, have you looked at the headers to see if data is getting sent back? Jquery tends to die silently - no errors as long as syntax is fine. This is a very helpful tool: http://livehttpheaders.mozdev.org/

--Brian Seagraves--
http://brianseagraves.com

I guess the tool that most

andirez - July 6, 2009 - 07:48

I guess the tool that most developers use nowadays for this is Firebug, the fantastic Firefox extension.

I noticed that there is an error in your SQL: ... {flag_content} SET cat = '%s' WHERE AND content_id ...

 
 

Drupal is a registered trademark of Dries Buytaert.