In Seditio if you call
plug.php?r=yourplug that would call a file from
plugins/code/yourplug.php as a standalone without header/footer. In Cotonti there is no such thing but it is replaced with so-called AJAX plugin parts.
AJAX-mode parts of plugins are standalone, without header/footer. They should use hook "ajax" and be called this way:
plug.php?r=yourplug which will call
plugins/yourplug/yourplug.php or
plugins/yourplug/yourplug.ajax.php or whatever you name it.
So, to create an AJAX part in your plugin you should:
- Create a part of the plugin, e.g. my_plug.ajax.php (could be any other name as well).
- Set its Hook=ajax.
- Code it just as a normal plugin, keeping in mind that it has not called header.php and footer.php. You can also set HTTP headers there with header() function before you send any output.
- Use it this way: plug.php?r=my_plug
Then you can call that part from other parts. Here is example jQuery code:
$.get('plug.php?r=my_plugin', { id: 123, name: 'Peter' },
function(data){
alert("Data Loaded: " + data);
});
Note that when submitting forms with GET (sometimes) or POST (always) you need to supply it with anti-XSS parameter
x. Here are PHP examples for GET and POST:
$t->assign('MY_JS_FUNC', "$.get('plug.php?r=my_plugin', { id: $id, x: '" . sed_sourcekey() . "' },
function(data){
alert('Data Loaded: ' + data);
});");
$t->assign('MY_JS_FUNC', "$.post('plug.php?r=my_plugin', { a: 'send', name: 'Peter', x: '" . sed_sourcekey() . "' },
function(data){
alert('Data Loaded: ' + data);
});");
If you need to submit a form from your document via AJAX you can use ajaxSend() function which will assemble it automatically:
ajaxSend({
url: 'plug.php?r=my_plugin',
method: 'POST',
formId: 'myformid'
})
Thanked: 3 times
Thanked: 12 times
A working example would be good.
ill have that example for you peeps in a minute.
Thanked: 12 times
Thanked: 10 times
What I mean is, can I get the content of:
Polls,Online,tagclous, news, new in forums (stuff that are in the index)
on a AJAX way...
I want to hide stuff from the index, and get it with AJAX when the user needs it... (ondemand)
hope to hear from someone
Thanked: 3 times
*bump* ?
I want to start learning how to incorporate ajax elements into plugins.