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

sanjayacloud's avatar

How to pass object as parameter to url in javascript

This is my JS

success: function (respond) {
                    if(respond.success){
                        //console.log(respond.orders);
                        window.location.href = "{{ url('client-orders/get-waybills-to-barcode-print-view-from-excel?orders=')}}"+respond.orders;
                    }
                },

if I console log this respond.orders, I got below result

Array(1)
0: {id: 1022, waybill_id: "20000021", client_id: 1, order_no: "Test Order Number", customer_name: "Test", …}
length: 1
__proto__: Array(0)

This is my method

public function getWaybillToBarcodeViewExcel(Request $request)
    {
        dd($request->all());
      

    }

In this dd(), I got below result

array:1 [▼
  "orders" => "[object Object]"
]

0 likes
8 replies
sanjayacloud's avatar

I got "URLSearchParams.getAll is not a function " error. I used it below.

 window.location.href = "{{ url('client-orders/get-waybills-to-barcode-print-view-from-excel?orders=')}}"+URLSearchParams.getAll(respond['orders']);
squiaios's avatar

And with that code ?

new URLSearchParams(respond['orders']).toString();
tykus's avatar

Did you new up the URLSearchParams? Why do you need getAll exactly?

let params = new URLSearchParams(yourObj);

window.location.href = "{{ url('client-orders/get-waybills-to-barcode-print-view-from-excel?orders=')}}" + params;
sanjayacloud's avatar

@tykus @squiaios

Now I got below error for both of your's solutions.

TypeError: Failed to construct 'URLSearchParams': The object must have a callable @@iterator property.

sanjayacloud's avatar
sanjayacloud
OP
Best Answer
Level 3

I have solved this problem with the below solution

   var params = respond.orders;
                        params = JSON.stringify(params);
                        // console.log(typeof params)
                        // //JSON.parse()
                        window.open("{{ url('client-orders/get-waybills-to-barcode-print-view-from-excel?orders=')}}" + params);

Please or to participate in this conversation.