[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ProgSoc] xmlhttp and a caching proxy
victor rajewski wrote:
The javascript I'm trying to tidy up... well... it involved an XMLHTTP
object, which opens a csv file to read some data. Problem is our
network is behind a caching proxy, and though the data has changed,
the proxy keeps on serving the old data. Is there a way to
force-reload (i.e. instruct the proxy to reload) when using
xmlhttp.open() ?
I had to use xmlhttp to send a POST request just last weekend, and this
[1] is how I did it.
This code (watch for wrapping!) uses xmlhttp to submit a 'form'
notifying the server that a page loaded with a request for a dead
fragment. (Like a 404 that your server never hears about.)
I don't actually read the response entity, but in the code below I've
shown how you can get it by passing a callback.
[1]
/*@cc_on @*/
var ExceptionMonitor = {
Report: function( exception ) {
// alert( exception );
}
};
// NOTE: the hardcoded value for the monitoring service is a default
// value only. The value is determined automatically and configured
// at run-time.
var FragmentMonitor = {
MonitoringService: "http://localhost/FragmentMonitor/";,
Run: function() {
var fragment = document.location.hash;
if ( fragment == null || fragment.length == 0 ) { return; }
fragment = fragment.replace( /#/, '' );
// alert( fragment );
try {
FragmentMonitor.VerifyFragment( document.location, fragment );
}
catch ( ex ) {
ExceptionMonitor.Report( ex );
}
},
VerifyFragment: function( location, fragment ) {
if ( ! FragmentMonitor.FindFragmentElement( document, fragment ) ) {
FragmentMonitor.ReportInvalidFragment( location, fragment );
}
},
FindFragmentElement: function( element, fragment ) {
var result = null;
if ( element.id == fragment || element.name == fragment ) { return
element; }
if ( element.hasChildNodes() ) {
for ( var i = 0; i < element.childNodes.length; i++ ) {
result = FragmentMonitor.FindFragmentElement(
element.childNodes[ i ], fragment );
if ( result ) { return result; }
}
}
},
ReportInvalidFragment: function( url, fragment ) {
var location = FragmentMonitor.MonitoringService;
var form_data = {
InvalidUrl: url,
MissingFragment: fragment
};
var callback = null;
// note: for debugging (or if you actually want the response)
// pass this callback to HttpRequest.PostForm
// to receive notification of request result.
callback = function( http_request ) {
if ( http_request.readyState == 4 ) {
alert( http_request.responseText );
}
}
HttpRequest.PostForm( location, form_data, callback );
}
};
var HttpRequest = {
PostForm: function( location, form_data, callback ) {
var http_request = HttpRequest.CreateRequest();
http_request.open( "POST", location, true );
if ( callback ) {
http_request.onreadystatechange = function() { return callback(
http_request ); }
}
http_request.setRequestHeader( "Content-Type",
"application/x-www-form-urlencoded" );
var encoded_form_data = "";
for ( var field in form_data ) {
if ( encoded_form_data != "" ) { encoded_form_data += "&"; }
encoded_form_data += field + "=" + encodeURIComponent( form_data[
field ] );
}
http_request.send( encoded_form_data );
},
CreateRequest: function() {
// see: http://jibbering.com/2002/4/httprequest.html
var result = null;
/*@if (@_jscript_version >= 5)
try { result = new ActiveXObject( "Msxml2.XMLHTTP" ); } catch (
ex ) { }
if ( result ) { return result; }
try { result = new ActiveXObject( "Microsoft.XMLHTTP" ); } catch
( ex ) { }
if ( result ) { return result; }
@end @*/
try { result = new XMLHttpRequest(); } catch ( ex ) { }
if ( result ) { return result; }
try { result = window.createRequest(); } catch ( ex ) { }
return result;
}
}
function load() {
// FragmentMonitor.Run();
}
function test() {
FragmentMonitor.Run();
}
-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.