PDA

View Full Version : AJAX xhr status when local?



GrndMasterFlash
January 13th, 2009, 06:22 PM
i am using a little AJAX to load text files onto a page for this xml/javascript blog engine im making, every thing is fine, but i want the engine to operate regardless if its on line or in a local folder.

the one hang up im hitting is when it's local there is no load status sent back from the server and as you can see by my code since there is not status the 200 (which mean OK it's loaded) never gets sent back


function do_xhr() {
// Step 1: Setup xhr_obj
if (window.XMLHttpRequest) {
xhr_obj = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr_obj = new ActiveXObject("Microsoft.XMLHTTP");
}

// Step 2: Setup asyn. handler.
xhr_obj.onreadystatechange = handle_xhr_obj;

//Step 3: Open request URL
xhr_obj.open("GET", "pages/blog/wacva_new.txt", true);

//Step 4: execute
xhr_obj.send(null);
}

function handle_xhr_obj() {
// alert("In handle_xhr_obj, readystate = " + xhr_obj.readyState);

if (xhr_obj.readyState == 4) {
alert("XHR complete");
if (xhr_obj.status == 200){
document.write("XHR successful. Message = " + xhr_obj.responseText);
}
}
}

how can i get it so that if the blog is ran local not from a server everything is still ligit and my file loads, when i comment out the if(xhr_obj.status == 200) part it will load, but then i think that would cause error when it's loading from a server

any ideas

borrob
January 14th, 2009, 05:52 AM
This status thing was introduced in ie 7 so if you're using an earlier version it's not there, and if your using ie 7 then you are using the wrong activex object.
microsoft has three versions:
XMLHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
depending on the version of ie...