You can use the URLSearchParams to convert an JS object to a query string
Aug 21, 2020
8
Level 3
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]"
]
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.