Hello all,
I’m using a technique from the Simply Javascript book to grab a value from a script using AJAX (without the X). I can’t see why I’m not getting the response I want.
I’m calling a url with some numbers tacked on the end. Typing this new total url into my browser gives me a page with other data on it. I’m trying to grab that other data.
I took out the setTimeout code because it was in the way of debugging, but that will be back in there later on.
Here’s some of my code
postcodePrice: function(input) {
var pc = input.value;
//bunch of code to clean pc, comes out as "pcnum", a 4-digit number
try {
var req = new XMLHttpRequest();
}
catch(err) {
try{
var req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(err) {
var req = null;
}
}
if(req != null) {
req.open('GET', 'http://example.com/grafkosten.php?postcode=' + pcnum, true);
req.onreadystatechange = function() {
if(req.readyState == 4) {
alert('ONREADYSTATECHANGE LOL');
[b]if(req.status == 200 || req.status == 304) {[/b]
alert('OH HAI 200OK');
}
else {
alert('OH NOES AJAX DUN BROKE');
}
}
};
req.send(null);
alert('now what?');
}
},
What’s happening is I do reach state 4 complete, but when I check to see if the status is 200 (which is is, I have confirmed and also it states this in Firebug), it goes to the else statement and alerts OH NOES.
Opera doesn’t give me any of the alerts. Safari and Chrome do. Is there something else I need to know about Opera?
I don’t know why. Am I asking for the status incorrectly? And I generally don’t have an issue with Firebug but here I just get the URL (and the 200 OK status) in the console and I can see the Headers I’ve sent, but not much else.
Where do I start?