3

im trying to send an array from javascript to Joomla 3.x php file.

var options = ['foo', 'bar'];

$.post('index.php?option=component&view=componentview&Itemid=123&tmpl=component&layout=xlsx', {'xlsx_options': options})

Then, I have a php file which creates data in order to download xlsx file. But I need to filter by this options array and Im not able to retrieve it. I've tried this without success.

$xlsx = $_POST['xlsx_options'];
$xlsx = json_decode($_POST['xlsx_options'], true);
$xlsx = JFactory::getApplication()->input->get('xlsx_options');

Any help? Thanks!

2
  • Do you need anymore help or was Lodder's answer the right one for you? Commented Aug 25, 2017 at 13:37
  • @Mark your question appears to be abandoned. If Lodder's answer solved your issue please award it the green tick. If there is still something to resolve, please leave a comment under the answer to isolate what is not yet right. Marking an accepted answer not only rewards the volunteer who best helps you, it signifies to future researchers that the answer indeed solves the issue. Commented Apr 6, 2018 at 2:04

1 Answer 1

1

You firstly need to encode your array in Javascript, like so:

var options = JSON.stringify(['foo', 'bar']);

$.post('index.php?option=component&view=componentview&Itemid=123&tmpl=component&layout=xlsx&options=' + options);

Then in your PHP code, use the following instead of $_POST:

$input = JFactory::getApplication()->input;
$xlsx  = json_decode($input->get('xlsx_options'));

echo $xlsx->foo;
echo $xlsx->bar;
1
  • Is it recommended to specify ->post() for this question? Commented Apr 6, 2018 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.