How can i set document.cookie in ajax?

the error i get

OPTIONS https://page/ net::ERR_EMPTY_RESPONSE

the reason that i tried to use a RequestHeader("Cookies", "test");

Login Failure: Browser did not support Cookie. Please enable Cookie.

what can i do to get around this ? like how does the browser send a header while options isn’t allowed ? sending a get request before the post request didn’t help because there wasn’t any response cookies .

some lines from the page source code that i think are important .

var strCookie = document.cookie;

document.cookie = cookie;

var cookie = "Language=en" + expires + ";

var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

even when i bypassed that error by running the code in the page console chrome tab … still

Please enable Cookie

so i tried

var cookie = "Language=en"

document.cookie = cookie;

and it worked but in the js file it didn’t even

console.log(document.cookie)

returns empty !

the full code

var cookie = "Language=en"

document.cookie = cookie;

console.log(document.cookie)

var xhr1 = new XMLHttpRequest();

xhr1.open ("post", ' https://page ', false);

xhr1.onreadystatechange = function() {

if (xhr1.readyState === XMLHttpRequest.DONE && xhr1.status === 200) {

var cookie = "Language=en"

document.cookie = cookie;

console.log(document.cookie)

}

}

xhr1.send("Username=test&Password=test");

Your browser just told you: enable cookie. Somewhere in “advanced settings” of browser you should to set “allow cookie for actual domain” or something like.

Enable Cookies and try again

1 Like

it’s already enabled it just doesn’t work in ajax !
the page sets the cookies using
document.cookie = cookie;
var cookie = "Language=en" + expires + ";
and ajax doesn’t execute js when requesting the page as a normal browser does … so the cookies doesn’t get set !
@backlinkercoming

the script must run on the same url/ip that you want to set the cookies on … you can’t set cookies for other sites simply using document.cookie = “cookie”;

maybe using something like this you can have two different ips in one url

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.