简体   繁体   中英

Why can't I parse HTML from a cookie in JavaScript

I have saved HTML code to a HTTP cookie which has been generated through JavaScript, however, JavaScript cannot parse the HTML and cuts off at the first double quote. See example below:

function loadBasket() {
    const loadHtml = document.cookie.split('; ').find(row => row.startsWith('itemHtml')).split('=')[1];

    console.log(loadHtml);
}

The console outputs

<li class=

It seem to be breaking on the first double quote. Is there a way for parse this as HTML?

.split('=')

right here in your code you are splitting by = and that's why the response is cut off at =

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM