I have a vmcustomplugin for products that really needs to be able to use AJAX/JSON to get values. The values come from internal tables and utilize some VM functions, so direct access to the file isn't an option. Since it's just a plugin, there's no controller or view. Is there a way to use AJAX in the plugin?
http://dev.virtuemart.net/projects/virtuemart/wiki/Product_Plugins
Thanks for the reply. I'm very familiar with the how the plugins work. I've developed a couple of them already. That doesn't answer my question though. Any ideas?
what type of plugin? explain what it does. There are many content plugins that run in vmart descriptions etc that use ajax,
Correct, and I've written a vmextended plugin that uses AJAX as well. But my extended plugin has it's own controller, model, and views, so I simply set up one of the views to handle the AJAX request. For example:
http://MYDOMAIN.COM/index.php?option=com_virtuemart&view=MYVIEW&task=getData&format=json&type=current&id=1
This would return a JSON object.
Now, for my product plugin, there is no view, no controller. It's just 2 files...the plugin php and the plugin XML located in plugins/vmcustom/. I can't use direct access like:
http://MYDOMAIN.COM/plugins/vmcustom/MYPLUGIN.php
because I need it to be able to leverage some VirtueMart functions and get data from the database. So how can I set up AJAX requests for this plugin?
If you're still interested in what it actually does, it's an elaboration on "related items" where you can define rules. This frees the content manager from constantly having to update related items manually since the rules automatically pull the freshest data. I've attached a screenshot of the plugin. Please keep in mind the question at hand isn't what the plugin does but how to get AJAX working. ;)
Thanks for your time!
[attachment cleanup by admin]
Hello
Not sure if this helps. I'm not very experimented with ajax. But from my little experience, what you need to do is to create a simple component to handle the ajax request from your plugin. so you'll call index.php?option=com_yourcomponent&format=raw from your plugin javascript. I never tryed with a vmcustom plugin (only used this method from a module) but I'm pretty sure this is a/the way.
Yeah, I was afraid that would be the only answer. You can also do it with a vmextended plugin to add a custom view to handle the AJAX requests and already be in the VirtueMart scope. I just didn't want to have to build a totally separate extension to handle the AJAX. If that's my only option, I guess I'll have to do that. Thanks for the input!