News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

VM Ajax request URL format

Started by cmsdev, September 29, 2022, 16:05:20 PM

Previous topic - Next topic

cmsdev

I'm trying to make an Ajax request in my custom vmshipment plugin and can't figure out the url format to use the function from the same plugin. Here's how my ajax code looks:

Quote
                                    jQuery.ajax(
                                    {
                                        type: "POST",
                                        dataType: "json",
                                        url: Virtuemart.vmSiteurl + "index.php?option=com_virtuemart&group=vmshipment&plugin=my_plugin_name&method=onAjaxMyFunction&format=json",
                                        success: function(data)
                                        {
                                             var response = jQuery.parseJSON(data);
                                             console.log(response);
                                        }
                                    });

onAjaxMyFunction looks like this

Quote
public function onAjaxMyFunction() {
        $data = array("test");
        return $data;
    }

I'm not getting an error but I'm not getting the correct data from the function as well. In the response section (in Firefox dev panel) I see only "ok: 0" and it isn't changing even when I'm trying to modify the url.

I spent a lot of time trying to solve that and I hope someone can help or tell me what I'm doing wrong.

cmsdev

Found this way of requesting in vmpayment/eway plugin:

Quote
request = {
                                      option: "com_virtuemart",
                                      view: "plugin",
                                      type: "vmshipment",
                                      tmpl: "raw",
                                      name: "my_plugin",
                                      action: "my_function"
                                    }
                                                                       
                                    jQuery.ajax(
                                    {
                                        type: "POST",
                                        dataType: "json",
                                        url: Virtuemart.vmSiteurl,
                                        data: request,
                                        success: function(data)
                                        {   
                                             var response = jQuery.parseJSON(data);
                                             console.log(response);
                                        },
                                        error: function() {
                                          alert("There was some error performing the AJAX call!");
                                        }
                                    });

But this request returns only a blank VM page with header and menu and doesn't return the function data.
Still trying to figure out why ajax requests don't work in the VM environment  ???

Studio 42

request = {
                                      option: "com_virtuemart",
                                      view: "plugin",
                                      type: "vmshipment",
                                      format: "raw"
                                    }

And you need a function in your plugin plgVmOnSelfCallFE