By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,166 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,166 IT Pros & Developers. It's quick & easy.

Ajax bizare

P: n/a
GTi
I have a bizare Ajax POST problem.
I use Ajax POST to send data to the server.
The server get the POST and answer back.
BUT if I POST the data once again I recieve the same answer that the
first post give me, even if the answer is different. I have used HTTP
Analyser Std V2.1.1.15 and I see that the answer is different. But the
Ajax .responseText is the same as the first POST. It looks like it use
the cached respons.
In the RFC the client should never use the cache if it is a POST.
And to make sure I have added a new serial=xxxx in the POST URL for
eatch requests.
But still get the same result as the first POST into the JavaScript
(but the respons from the server IS different).

Here is the server responses from HTTP Analyser:
----------------------------------------
(Request-Line):POST /page.aspx?EditMaster=0&serial=1159541629765
HTTP/1.1
Host:127.0.0.1
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7)
Gecko/20060909 Firefox/1.5.0.7
Accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language:nb
Accept-Encoding:gzip,deflate
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive:300
Connection:close
Content-Type:application/x-www-form-urlencoded
Cache-Control:post-check=0, pre-check=0, no-cache
Pragma:no-cache, no-cache
Content-Length:3695
Cookie:WebSelectTabWorkShiftWebTab2=1; WebSelectTabRealTPIWebTab2=2
-----------------------------------------
(Status-Line):HTTP/1.1 200 OK
Server:Microsoft-IIS/5.1
Date:Fri, 29 Sep 2006 14:53:49 GMT
X-Powered-By:ASP.NET
Connection:close
X-AspNet-Version:2.0.50727
ABB:MES
Set-Cookie:ASP.NET_SessionId=kfrv5c55kbeefemshid2ki45; path=/; HttpOnly
Cache-Control:no-cache
Pragma:no-cache
Expires:-1
Content-Type:text/html; charset=utf-8
Content-Length:239
Here is the JavaScript Code:
function AjaxFormPostItMakeRequest(url, data)
{
[snippet .. AjaxForm = new XMLHttpRequest() ... blabla]
AjaxForm.onreadystatechange = AjaxFormPostItalertContents;
AjaxForm.open('POST', url, true);
AjaxForm.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
AjaxForm.setRequestHeader("Content-length", data.length);
AjaxForm.setRequestHeader("Connection", "close");
AjaxForm.setRequestHeader("Cache-Control", "no-store, no-cache,
must-revalidate");
AjaxForm.setRequestHeader("Cache-Control", "post-check=0,
pre-check=0");
AjaxForm.setRequestHeader("Pragma", "no-cache");
AjaxForm.send(data);
}

function AjaxFormPostIt(obj)
{
var getstr = '';
[ snippet - get all the post elements]
var timestamp = new Date().getTime();
var url = '/page.aspx?EditMaster=0&serial=' + timestamp;
AjaxFormPostItMakeRequest(url, getstr);
}
Anyone can help me out here - please?
GTi

Sep 29 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a

GTi wrote:
I have a bizare Ajax POST problem.
I use Ajax POST to send data to the server.
The server get the POST and answer back.
BUT if I POST the data once again I recieve the same answer that the
first post give me, even if the answer is different. I have used HTTP
Analyser Std V2.1.1.15 and I see that the answer is different. But the
Ajax .responseText is the same as the first POST. It looks like it use
the cached respons.
In the RFC the client should never use the cache if it is a POST.
And to make sure I have added a new serial=xxxx in the POST URL for
eatch requests.
But still get the same result as the first POST into the JavaScript
(but the respons from the server IS different).

Here is the server responses from HTTP Analyser:
----------------------------------------
(Request-Line):POST /page.aspx?EditMaster=0&serial=1159541629765
HTTP/1.1
Host:127.0.0.1
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7)
Gecko/20060909 Firefox/1.5.0.7
Accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language:nb
Accept-Encoding:gzip,deflate
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive:300
Connection:close
Content-Type:application/x-www-form-urlencoded
Cache-Control:post-check=0, pre-check=0, no-cache
Pragma:no-cache, no-cache
Content-Length:3695
Cookie:WebSelectTabWorkShiftWebTab2=1; WebSelectTabRealTPIWebTab2=2
-----------------------------------------
(Status-Line):HTTP/1.1 200 OK
Server:Microsoft-IIS/5.1
Date:Fri, 29 Sep 2006 14:53:49 GMT
X-Powered-By:ASP.NET
Connection:close
X-AspNet-Version:2.0.50727
ABB:MES
Set-Cookie:ASP.NET_SessionId=kfrv5c55kbeefemshid2ki45; path=/; HttpOnly
Cache-Control:no-cache
Pragma:no-cache
Expires:-1
Content-Type:text/html; charset=utf-8
Content-Length:239
Here is the JavaScript Code:
function AjaxFormPostItMakeRequest(url, data)
{
[snippet .. AjaxForm = new XMLHttpRequest() ... blabla]
AjaxForm.onreadystatechange = AjaxFormPostItalertContents;
AjaxForm.open('POST', url, true);
AjaxForm.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
AjaxForm.setRequestHeader("Content-length", data.length);
AjaxForm.setRequestHeader("Connection", "close");
AjaxForm.setRequestHeader("Cache-Control", "no-store, no-cache,
must-revalidate");
AjaxForm.setRequestHeader("Cache-Control", "post-check=0,
pre-check=0");
AjaxForm.setRequestHeader("Pragma", "no-cache");
AjaxForm.send(data);
}

function AjaxFormPostIt(obj)
{
var getstr = '';
[ snippet - get all the post elements]
var timestamp = new Date().getTime();
var url = '/page.aspx?EditMaster=0&serial=' + timestamp;
AjaxFormPostItMakeRequest(url, getstr);
}
Anyone can help me out here - please?
GTi
You need to set some Content Headers when your server resource replies:

Cache_control: no-cache
Pragma: no-cache

This will tell the UA to always get a new response, not use one from
cache.

Sep 29 '06 #2

P: n/a

Tom Cole wrote:
GTi wrote:
I have a bizare Ajax POST problem.
I use Ajax POST to send data to the server.
The server get the POST and answer back.
BUT if I POST the data once again I recieve the same answer that the
first post give me, even if the answer is different. I have used HTTP
Analyser Std V2.1.1.15 and I see that the answer is different. But the
Ajax .responseText is the same as the first POST. It looks like it use
the cached respons.
In the RFC the client should never use the cache if it is a POST.
And to make sure I have added a new serial=xxxx in the POST URL for
eatch requests.
But still get the same result as the first POST into the JavaScript
(but the respons from the server IS different).

Here is the server responses from HTTP Analyser:
----------------------------------------
(Request-Line):POST /page.aspx?EditMaster=0&serial=1159541629765
HTTP/1.1
Host:127.0.0.1
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7)
Gecko/20060909 Firefox/1.5.0.7
Accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language:nb
Accept-Encoding:gzip,deflate
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive:300
Connection:close
Content-Type:application/x-www-form-urlencoded
Cache-Control:post-check=0, pre-check=0, no-cache
Pragma:no-cache, no-cache
Content-Length:3695
Cookie:WebSelectTabWorkShiftWebTab2=1; WebSelectTabRealTPIWebTab2=2
-----------------------------------------
(Status-Line):HTTP/1.1 200 OK
Server:Microsoft-IIS/5.1
Date:Fri, 29 Sep 2006 14:53:49 GMT
X-Powered-By:ASP.NET
Connection:close
X-AspNet-Version:2.0.50727
ABB:MES
Set-Cookie:ASP.NET_SessionId=kfrv5c55kbeefemshid2ki45; path=/; HttpOnly
Cache-Control:no-cache
Pragma:no-cache
Expires:-1
Content-Type:text/html; charset=utf-8
Content-Length:239
Here is the JavaScript Code:
function AjaxFormPostItMakeRequest(url, data)
{
[snippet .. AjaxForm = new XMLHttpRequest() ... blabla]
AjaxForm.onreadystatechange = AjaxFormPostItalertContents;
AjaxForm.open('POST', url, true);
AjaxForm.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
AjaxForm.setRequestHeader("Content-length", data.length);
AjaxForm.setRequestHeader("Connection", "close");
AjaxForm.setRequestHeader("Cache-Control", "no-store, no-cache,
must-revalidate");
AjaxForm.setRequestHeader("Cache-Control", "post-check=0,
pre-check=0");
AjaxForm.setRequestHeader("Pragma", "no-cache");
AjaxForm.send(data);
}

function AjaxFormPostIt(obj)
{
var getstr = '';
[ snippet - get all the post elements]
var timestamp = new Date().getTime();
var url = '/page.aspx?EditMaster=0&serial=' + timestamp;
AjaxFormPostItMakeRequest(url, getstr);
}
Anyone can help me out here - please?
GTi

You need to set some Content Headers when your server resource replies:

Cache_control: no-cache
Make that Cache-Control (dash, not underscore)...Sorry.
Pragma: no-cache

This will tell the UA to always get a new response, not use one from
cache.
Sep 29 '06 #3

P: n/a
VK

Tom Cole wrote:
Cache-Control: no-cache
Pragma: no-cache

This will tell the UA to always get a new response, not use one from
cache.
A small correction: the last one (Pragma) doesn't handle the UA's cache
mechanics. It instructs the intermediary servers do not serve the
request from their proxies but to re-request the source server (where
understood of course).

Sep 29 '06 #4

P: n/a
GTi
VK wrote:
Tom Cole wrote:
Cache-Control: no-cache
Pragma: no-cache

This will tell the UA to always get a new response, not use one from
cache.

A small correction: the last one (Pragma) doesn't handle the UA's cache
mechanics. It instructs the intermediary servers do not serve the
request from their proxies but to re-request the source server (where
understood of course).
Is't it already here:

(Status-Line):HTTP/1.1 200 OK
Server:Microsoft-IIS/5.1
Date:Fri, 29 Sep 2006 14:53:49 GMT
X-Powered-By:ASP.NET
Connection:close
X-AspNet-Version:2.0.50727
ABB:MES
Set-Cookie:ASP.NET_SessionId=kfrv5c55kbeefemshid2ki45; path=/; HttpOnly
Cache-Control:no-cache
<------------------------------------------------------
Pragma:no-cache
<---------------------------------------------------------------
Expires:-1
Content-Type:text/html; charset=utf-8
Content-Length:239

Sep 29 '06 #5

P: n/a
VK
Cache-Control: no-cache
Pragma: no-cache

Is't it already here:

(Status-Line):HTTP/1.1 200 OK
Server:Microsoft-IIS/5.1
<snip>

Firefox has POST problems with some versions of IIS, because some IIS
are using a non-standard packets split-off in response (if not
patched). IE likes it, Firefox wants it in the conventional way. Search
bugzilla.mozilla.org for "IIS server POST packet length", I don't have
the exact bug URL. I'm not saying it is the reason: just one more
direction to look at. Maybe c.i.w.a.h. and mozilla.org can be more
helpful.

Sep 30 '06 #6

P: n/a
GTi
VK wrote:
Cache-Control: no-cache
Pragma: no-cache
Is't it already here:

(Status-Line):HTTP/1.1 200 OK
Server:Microsoft-IIS/5.1
<snip>

Firefox has POST problems with some versions of IIS, because some IIS
are using a non-standard packets split-off in response (if not
patched). IE likes it, Firefox wants it in the conventional way. Search
bugzilla.mozilla.org for "IIS server POST packet length", I don't have
the exact bug URL. I'm not saying it is the reason: just one more
direction to look at. Maybe c.i.w.a.h. and mozilla.org can be more
helpful.
Thanks VK, I will try searching for it at mozilla.org.
However I got the same problem with IE !

Sep 30 '06 #7

P: n/a
GTi
OK, Ajax IS now reported fit :)
I tested it a little more and added a alert in my function:

function AjaxFormPostItalertContents()
{
if(AjaxForm.readyState == 4)
{
if (AjaxForm.status == 200)
{
var result = AjaxFormPostItHTTPRequest.responseText;
alert(result);
document.getElementById('PostInformationWindow').i nnerHTML =
result;
}
else
{
alert('There was a problem with the request.');
}
}
}

In the alert window I did see that the values from the server was
changed,
but NOT in the 'PostInformationWindow' <div>
How come ?

GTi wrote:
I have a bizare Ajax POST problem.
I use Ajax POST to send data to the server.
The server get the POST and answer back.
BUT if I POST the data once again I recieve the same answer that the
first post give me, even if the answer is different. I have used HTTP
Analyser Std V2.1.1.15 and I see that the answer is different. But the
Ajax .responseText is the same as the first POST. It looks like it use
the cached respons.
In the RFC the client should never use the cache if it is a POST.
And to make sure I have added a new serial=xxxx in the POST URL for
eatch requests.
But still get the same result as the first POST into the JavaScript
(but the respons from the server IS different).

Here is the server responses from HTTP Analyser:
----------------------------------------
(Request-Line):POST /page.aspx?EditMaster=0&serial=1159541629765
HTTP/1.1
Host:127.0.0.1
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7)
Gecko/20060909 Firefox/1.5.0.7
Accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language:nb
Accept-Encoding:gzip,deflate
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive:300
Connection:close
Content-Type:application/x-www-form-urlencoded
Cache-Control:post-check=0, pre-check=0, no-cache
Pragma:no-cache, no-cache
Content-Length:3695
Cookie:WebSelectTabWorkShiftWebTab2=1; WebSelectTabRealTPIWebTab2=2
-----------------------------------------
(Status-Line):HTTP/1.1 200 OK
Server:Microsoft-IIS/5.1
Date:Fri, 29 Sep 2006 14:53:49 GMT
X-Powered-By:ASP.NET
Connection:close
X-AspNet-Version:2.0.50727
ABB:MES
Set-Cookie:ASP.NET_SessionId=kfrv5c55kbeefemshid2ki45; path=/; HttpOnly
Cache-Control:no-cache
Pragma:no-cache
Expires:-1
Content-Type:text/html; charset=utf-8
Content-Length:239
Here is the JavaScript Code:
function AjaxFormPostItMakeRequest(url, data)
{
[snippet .. AjaxForm = new XMLHttpRequest() ... blabla]
AjaxForm.onreadystatechange = AjaxFormPostItalertContents;
AjaxForm.open('POST', url, true);
AjaxForm.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
AjaxForm.setRequestHeader("Content-length", data.length);
AjaxForm.setRequestHeader("Connection", "close");
AjaxForm.setRequestHeader("Cache-Control", "no-store, no-cache,
must-revalidate");
AjaxForm.setRequestHeader("Cache-Control", "post-check=0,
pre-check=0");
AjaxForm.setRequestHeader("Pragma", "no-cache");
AjaxForm.send(data);
}

function AjaxFormPostIt(obj)
{
var getstr = '';
[ snippet - get all the post elements]
var timestamp = new Date().getTime();
var url = '/page.aspx?EditMaster=0&serial=' + timestamp;
AjaxFormPostItMakeRequest(url, getstr);
}
Anyone can help me out here - please?
GTi
Sep 30 '06 #8

P: n/a
VK

GTi wrote:
In the alert window I did see that the values from the server was
changed,
but NOT in the 'PostInformationWindow' <div>
How come ?
Nasty gobblins in your computer? :-)
That must be some communication problem with 'PostInformationWindow',
without an actual page it's difficult to say. From the most recent
"misteries" of this kind: are you using full-qualified page with
<html>, <headand <body: or a "lazy version" with body elements
only? (Firefox spits on the last one).

Sep 30 '06 #9

P: n/a
GTi
VK wrote:
GTi wrote:
In the alert window I did see that the values from the server was
changed,
but NOT in the 'PostInformationWindow' <div>
How come ?

Nasty gobblins in your computer? :-)
That must be some communication problem with 'PostInformationWindow',
without an actual page it's difficult to say. From the most recent
"misteries" of this kind: are you using full-qualified page with
<html>, <headand <body: or a "lazy version" with body elements
only? (Firefox spits on the last one).
LOL
The whole page is rater big but it is html verified with FireFox.
I guess it is something in my code somwhere.
Topic locked.

Sep 30 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.