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

xmlrequest status codes

P: 2
Hello,

below the fragment that works fine, but nevertheless, the value of xmlhttp.status
turns out to be zero (0), and the corresponding value for xmlhttp.statusText is "unknown".

Does anyone know the details of ALL the statuscodes when the value for readyState is 4 (= completed).


Also, where could I have found the answer myself???

thanks,

Frens


xmlhttp.open("GET", "test.txt",true);
xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4) {
window.alert("Show the stuff");}
}
xmlhttp.send(null)

window.alert(xmlhttp.readyState);
window.alert(xmlhttp.responsetext);
window.alert(xmlhttp.responseXML);
window.alert(xmlhttp.status);
window.alert(xmlhttp.statusText);
Mar 16 '07 #1
Share this Question
Share on Google+
4 Replies


P: 2
Hello,

anyone know why status code after the GET and SEND is 0?

It should be 200 since the file has been loaded and can be assessed.

thanks,

Frens



<script type="text/javascript">


var xmlhttp;

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

if (xmlhttp) {
document.write('<p class="example"><a href="#" onclick="example();return false;">Try the example.</a></p>')
}

function example() {

xmlhttp.open("GET","just some text.txt",true);
xmlhttp.onreadystatechange=function() {


if (xmlhttp.readyState == 4)
if (xmlhttp.status == 200)
alert("Server is done!");
else if (xmlhttp.status == 404)
alert("Request URL does not exist");
else
alert("Error: status code is " + xmlhttp.status);

if (xmlhttp.readyState==4) {
if (xmlhttp.status==0) { // !! This should be 200 since all seems right

var local=new Function("return "+xmlhttp.responseText)();
window.alert(xmlhttp.responseText);

window.alert("Code - Name\n"+local[0].id+' - '+local[0].name);

} else {
alert("not found");
}

} // end statechangefunction

} // end example function

xmlhttp.send(null);

}
</script>
Mar 17 '07 #2

P: 12
Hi,

Your ajax code seems to rely on IE (activeX). Try looking at

http://www-128.ibm.com/developerworks/web/library/wa-ajaxintro1.html

And use the cross-browser Ajax code.
Mar 17 '07 #3

P: 12
xmlhttp.open("GET", "test.txt",true);
xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4) {
window.alert("Show the stuff");}
}
xmlhttp.send(null)

window.alert(xmlhttp.readyState);
window.alert(xmlhttp.responsetext);
window.alert(xmlhttp.responseXML);
window.alert(xmlhttp.status);
window.alert(xmlhttp.statusText);
Here's a link:

http://developer.apple.com/internet/...mlhttpreq.html

Check out table 2.
Mar 17 '07 #4

acoder
Expert Mod 15k+
P: 16,027
Merged threads.
Mar 19 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.