Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / September 2006



Tip: Looking for answers? Try searching our database.

Ajax bizare

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GTi - 29 Sep 2006 18:30 GMT
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
Tom Cole - 29 Sep 2006 19:11 GMT
> I have a bizare Ajax POST problem.
> I use Ajax POST to send data to the server.
[quoted text clipped - 72 lines]
> 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.
Tom Cole - 29 Sep 2006 19:12 GMT
> > I have a bizare Ajax POST problem.
> > I use Ajax POST to send data to the server.
[quoted text clipped - 76 lines]
>
> 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.
VK - 29 Sep 2006 19:38 GMT
> 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).
GTi - 29 Sep 2006 23:19 GMT
> > Cache-Control: no-cache
> > Pragma: no-cache
[quoted text clipped - 6 lines]
> 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
VK - 30 Sep 2006 08:26 GMT
> > Cache-Control: no-cache
> > Pragma: no-cache
[quoted text clipped - 3 lines]
>  (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.
GTi - 30 Sep 2006 10:06 GMT
> > > Cache-Control: no-cache
> > > Pragma: no-cache
[quoted text clipped - 12 lines]
> 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 !
GTi - 30 Sep 2006 11:17 GMT
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').innerHTML =
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 ?

> I have a bizare Ajax POST problem.
> I use Ajax POST to send data to the server.
[quoted text clipped - 72 lines]
> Anyone can help me out here - please?
> GTi
VK - 30 Sep 2006 18:15 GMT
> 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>, <head> and <body> : or a "lazy version" with body elements
only? (Firefox spits on the last one).
GTi - 30 Sep 2006 19:04 GMT
> > In the alert window I did see that the values from the server was
> > changed,
[quoted text clipped - 7 lines]
> <html>, <head> and <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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.