Forum Moderators: open

Message Too Old, No Replies

jQuery .get()/.post() doesn't send an updated cookie

         

MarkusS

7:04 pm on May 18, 2010 (gmt 0)

10+ Year Member



Hello,

I'am doing something like this:


function setCookie(name, value, expire) {
var exdate = new Date();
exdate.setDate(exdate.getDate()+expire);
document.cookie=name+ "=" +escape(value)+((expire==null) ? "" : ";expires="+exdate.toGMTString());
}


// When I click a button
// Update the cookie
setCookie("test", "1");

function getContent() {
// Get the data of our new URL
$.get("index.php", loadContent);
}

function loadContent(data) {
// alert the new title
// the PHP script is changing title after what cookie-value you have
alert($("title", data).text())
}


First of all, when Iam alerting it is still the last <title> showing up. So I guess it doesn't send the changed cookies at all.. And for some reason I don't see the request in my Live HTTP Headers window...

But also, if i request the URL(without the ajax) it works just fine

What am I doing wrong here?

Regards MarkusS

daveVk

3:09 am on May 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$.get("index.php", loadContent);

gets cached version of index.php

try $.post OR add cache buster to url eg timestamp