Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataCloneError: The object could not be cloned

I have ajax search based web (filter with inputs and results) where i want make working back/foward browser button. So i must use window.history.pushState witch is working with contetnt (search results) but i must 'store' whole filter with inputs and selected values.

On filter inputs i am using SumoSelect plugin and if you store all html elements to variable and after that append it back to DOM (after press back button) functionality of SumoSelect is not working any more...

Here is my question about it. One possible solution (what i know) how make it works after append is use .contents() instead of .html().

BUT if i use .contents() in pushState like this:

 window.history.pushState({"html":results,"filter": $('#filter').contents(),"pageTitle":"title"},"", null);

I get error:

DataCloneError: The object could not be cloned.

So is there any options how store filter to state to make it work?

like image 739
Lajdák Marek Avatar asked Feb 04 '23 07:02

Lajdák Marek


1 Answers

The pushState location state object must be serializable, which means no methods. $('#filter').contents() returns a jQuery object that can't be serialized.

Try turning the contents into an object or array.

like image 130
HertzaHaeon Avatar answered Feb 17 '23 07:02

HertzaHaeon