Jeditable and admin-ajax.php in WordPress

Jeditable is an awesome in-line editor plugin for jQuery. I was trying to use it with WordPress the other day and I had a little trouble that went like this.

A basic invocation of Jeditable is for example:


$('.edit').editable('http://www.example.com/save.php', {
"callback": function( sValue, y ) {
alert("callback");
},
"submitdata": function ( value, settings ) {
return {
"action": 'edit_item'
};
}
});

The first argument is the URL or function to send the edited content to. The problem when using this with WordPress is that you will end up with a separated file (the save.php) that will be isolated from the WordPress environment. Wouldn’t it be better to run this as a normal WordPress AJAX call?

To use this with WordPress you just need to use as a target the wp-admin/admin-ajax.php and have the action name in the submitdata, e.g.:


$('.edit').editable( '/wp-admin/admin-ajax.php', {
"callback": function( sValue, y ) {
alert("callback");
},
"submitdata": function ( value, settings ) {
return {
"action": 'edit_item'
};
}
} );

Then you can define that AJAX action and access everything on the WordPress side (database, etc).

3 thoughts on “Jeditable and admin-ajax.php in WordPress

  1. Hey Nuno, I guess you are brazilian (or at least your portuguese speaker) so I'll write the following in portuguese:

    Tô montando a estrutura de um site com todos os apps pra Boxee (a iniciativa é minha devido à necessidade, não sei se vc conhece Boxee.tv )

    Eu quero deixar ele fácil de atualizar, pra usuários registrados. E dar um funcionamento de wiki pra essa instalação do wordpress, daí quero oferecer campos editáveis para algumas "taxonomies" usando Jeditable. Eu sou bem newbie em php, mas manjo bem de html e pra implementar é sem problemas, mas só zero a esquerda em tabelas de SQL.

    Você acha que rola usar o Jeditable, e as mudanças serão computadas como revisão?

    Valeu!

  2. Ian, I'm not sure and I don't have the time right now to check it. Why don't you try it out and let us all know? :)

    Cheers,

    Nuno

Comments are closed.