0
votes

I have a challenge that is bugging me. The thing is - I'm creating a plugin that is doing an AJAX call to another file in this plugin. It seems Joomla is preventing me from accessing that file.

I need to POST to a file that returns data from a SOAP call.

I'm calling the file from this line:

$html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';

I've tried both a relative, absolute and server path as well - Joomla doesn't like it. But I can't remember or find the correct way to do it.

The file is in the same folder as the plugin that outputs above code.

Here's the complete javascript function my plugin outputs:

$html .= '<script type="text/javascript">';

    $html .= 'function searchParcels()';
    $html .= '{';
        $html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';
            $html .= 'function(data) {';

                $html .= 'var shops = $.parseJSON(data);';
                $html .= '$(\'#shops_output\').html(\'\');';

                $html .= 'for(i in shops)';
                $html .= '{';
                    $html .= 'var html = \'<p>\'';
                    $html .= '+ shops[i][\'CompanyName\'] + \'<br>\'';
                    $html .= '+ shops[i][\'Streetname\'] + \'<br>\'';
                    $html .= '+ shops[i][\'ZipCode\'] + \' \' + shops[i][\'CityName\'] + \'<br>\'';
                    $html .= '+ shops[i][\'Telephone\'] + \'<br>\'';
                    $html .= '+ \'</p>\';';
                    $html .= '$(\'#shops_output\').append(html);';
                $html .= '}';

            $html .= '});'; 
    $html .= '}';

$html .= '</script>';

Any help is greatly appreciated :-) Thanks.

1

1 Answers

1
votes

Please check this post on how to use Joomla's ajax interface (it seems you are not using it). This is much easier and much cleaner (and much more standard) than the method you described. All you need to do is to create the module/plugin (make sure that you have a function name ending with "Ajax") and then issue the right call from anywhere on your Joomla website (make sure you use the URL pattern described on the website).