Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LuisAduana's avatar

How pass param route if the param is on JS file

Hi. I'm trying to create a PDF with DOMPDF.

I have a list on my view.blade.php when I select each item I save the id in a variable on mi script file.

When the user finish to select the items then press the button "Generate" and call PDFController but I need pass it the array of IDs for query to database in PDF Controller.

I hope you can help me :D

In my view I have something like this

<a href="{{ route('generarPdf', $arrayIDs) }}" class="btn wbtn-pill btn-md mr-2"> Imprimir PDF </a>

$arrayIDs is the param wich I need pass

And in the script I have this

require(['jquery',
         ...etc...
         'jquery.validate.lang'
], function($) {
    
    console.log('<profesionistas> SCRIPT LOADED SUCCESSFULLY')
    $(document).ready(function() {
        console.log('<profesionistas::document[ready]> DOM ready');
	...etc...
	var arrayIDs = [];
0 likes
5 replies
Niush's avatar

If you are using Ajax or Axios, you could do something like:

$.ajax({
        url: "/generate/pdf",
        type: "post",
        data: {
		"id": [1,2,3,4]
	},
        success: function(res) {
            console.log(res);
        }
});

Or, If you are using normal Form Request:

In a hidden input field set value to array of ids.

<input type="hidden" value="[1,2,3,4]" name="id"/>

Then, in the Laravel decode it as:

$ids = json_decode(request('id'));
LuisAduana's avatar

I'm using something like this

<a href="{{ route('generatePDF', ['idTitulos' => $arrayIDs]) }}" class="btn wbtn-pill btn-md mr-2"> Imprimir PDF </a>

$arrayIDs is the param

If I use JQuery when I call the controller then it return me a code pdf in console :/

Sinnbeck's avatar

The code is made to generate a pdf. Not download it.

Please or to participate in this conversation.