/    Sign up×
Community /Pin to ProfileBookmark

Problems with HTTPRequest

I’m having problem getting HTTPRequest to work the way I want. Greatly simplified code below (IE only shown).

I have a page that tracks a number of updates, occuring elsewhere, to a database. Click on ‘Test It’ and the latest number is displayed without having to refresh the page. (bit like a stock ticker)

In this example, the ‘alert’ box shows the number (returned by the test.cgi script). Update the number in test.cgi (in another window), click ‘Test It’ and the new number should be displayed.

On my local machine it all works as expected but when working on the server, the original number, not the updated number, is displayed. (test.cgi simply returns a ‘text/plain’ number).

Now here’s the really strange part.
If I run the test.cgi in a different window (on the same machine) it returns the updated number. Now if I go back and click ‘Text It’ the updated number is displayed. (test.cgi simply returns the latest number from the database)

I hope I explained that so you can understand the problem.

[code][size=1]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

<html><head><title>untitled</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<meta http-equiv=”Content-Script-Type” content=”text/javascript”>
<meta http-equiv=”Content-Style-Type” content=”text/css”>
<script type=”text/javascript”>
<!–
var xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);

function http_test() {
xmlhttp.open(“GET”,”/cgi-bin/test.cgi?data”,true);
xmlhttp.onreadystatechange = get_data;
xmlhttp.send(null);
}

function get_data() {
if (xmlhttp.readyState == 4) {
alert(xmlhttp.responseText);
}
}
//–>
</script>
</head>

<body>
<p><a href=”” onclick=”http_test(); return false;”>Test It</a></p>
</body>
</html>
[/size][/code]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@NedalsauthorFeb 26.2005 — Problem solved!

The test.cgi was being cached even though I had a no-cache meta tag. It turns out that it did not apply to test.cgi. So I sent a HTTP no-cache header prior to the data.
Copy linkTweet thisAlerts:
@Khalid_AliFeb 27.2005 — did u do that using httprequest object?
Copy linkTweet thisAlerts:
@NedalsauthorFeb 27.2005 — [i]Originally posted by Khalid Ali [/i]

[B]did u do that using httprequest object? [/B][/QUOTE]
Yes. Here's the code I used for the cross-browser application
[size=1]
var xmlDoc = null;
function load_data() {
if (typeof window.ActiveXObject != 'undefined' ) {
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
xmlDoc.onreadystatechange = get_data;
} else {
xmlDoc = new XMLHttpRequest();
xmlDoc.onload = get_data;
}
xmlDoc.open("GET","/cgi-bin/test.cgi?data",true);
xmlDoc.send(null);
}

function get_data() {
if (xmlDoc.readyState != 4) return; // upload complete
alert(xmlDoc.responseText); // Relaced to display on page
}
[/size]
Copy linkTweet thisAlerts:
@NedalsauthorFeb 28.2005 — [i]Originally posted by Khalid Ali [/i]

[B]did u do that using httprequest object? [/B][/QUOTE]
Might be a good idea to read your question. ?

No, I used the following lines of code in my Perl script.
[size=1]
print "Content-Type: text/plainn";
print "Pragma: no-cachenn";
print "Cache_Control: no-store,no-cache,must-revalidate,post-check=0,pre-check=0nn";
[/size]
Copy linkTweet thisAlerts:
@Khalid_AliFeb 28.2005 — [i]Originally posted by Nedals [/i]

[B]Might be a good idea to read your question. ?

[/B]
[/QUOTE]


lol.. thats allright.

The reason I asked was that you could do that using HttpRequest object as well and I wondered if you got into any problem doing that(browser security etc)
×

Success!

Help @Nedals spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...