简体   繁体   中英

HTTP GET request in Javascript with Cookie?

I need to do an HTTP GET request in JS, with a pre-definied cookie.

What would be the best way to to that?

Found that, with many ways to do an request, but found no one that supports cookies... HTTP GET request in JavaScript?

You can't set cookies for a specific request, but you can edit cookies on the clientside if you set them as such.

This cookies script abstracts this aways a bit, because you only have access to the full string, containing all of the cookies in one via document.cookie , natively.

Depending on you want to do, you might be better off setting GET parameters instead.

    if(!isset($_COOKIE["cookiename"])) {
        setcookie("cookiename","cookievalue");
    } else {
        // This is propably the 2nd call of that site (with cookie)
        // Here your code comes
    }

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