We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Ajax calls to update the database from an accessory

Development and Programming

Symon Pritchett's avatar
Symon Pritchett
11 posts
14 years ago
Symon Pritchett's avatar Symon Pritchett

I’m trying to update the database using an ajax call from an accessory:

Every thing is working with the accessory, but I am making an Ajax call outside of EE framework to update the database. But I want to do this Ajax update withing the EE framework.

On this development page for EE: http://ellislab.com/expressionengine/user-guide/development/accessories.html

There is this bit: Processing Requests

Accessories have the ability to process requests for actions like AJAX calls. The following URL would be called C=addons_accessories&M=process_request&accessory=my_accessory&method=process_sample_process that requests the process_sample_process method in my_accessory

So I added the Ajax call:

$.ajax({
    type    : 'POST',
    url     : 'C=addons_accessories&M=process_request&accessory=hb_publish_help&method=update_help',
    data    : settings.data,
    success : function(msg){
        $(original_html).html(ckeip_html);
        $('#ckeip_' + u_id + '').hide();
        $(original_html).fadeIn();
          console.log〈msg〉;
    }
});
  • The message being logged in the console is the html of the redirect page (it’s inside another js file and is working and passing the correct data when I use an external file to update the DB)

Is there a setting I need to have that allows ajax calls to be made in the system?

And this function inside my acc. file

function update_help(){
        if($this->EE->input->post('update_help') != ''){        
            $channel_id = "".$this->EE->input->get('channel_id');
            // check if entry exists
            $this->EE->db->select('file_id');
            $this->EE->db->from('exp_hb_publish_help');
            $this->EE->db->where('channel_id', $channel_id);
            $check = $this->EE->db->get();    
            if($check->num_rows() > 0){
                $data = array('help_text' => $text);
                $this->db->where('channel_id', $channel_id);
                $this->db->update('exp_hb_publish_help', $data); 
            }
            else {
                $data = array('help_text' => $text, 'channel_id' => $channel_id);
                $this->db->insert('exp_hb_publish_help', $data); 
            }
            // Kill EE Execution
            exit();
        }
    }

Moved to Development and Programming by Moderator

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
14 years ago
Sue Crocker's avatar Sue Crocker

Hi Symon Pritchett, Excellent questions, but better suited for the Developer forums… moving for additional community support.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.