-1

I have a web application that I'm building using, what I thought, is a simple Ajax function. The app works great on four out of five computers here in the office, but one computer has a problem reaching the status of 200. And it's not really a browser specific issue either. He's tried the app on IE, Chrome, Firefox, & Safari and same issue on all four browsers.

This is something that we really have to figure out and correct on our end before the product goes into full production. After that we can't be running around correcting customers computers or trying to explain to the customer that it's their computer that's at fault.

So any ideas?

Notes:

  1. The Ajax function, queried PHP script, and database are all on the same server.
  2. His computer is running Windows 7 on a Pavilion DV7 computer

Code:

// Pull the information from the database
get_variables = 'action=grabUnitInformation'+
'&identifier='+identifier;

var xmlhttp;
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
    var receiver = eval('(' + xmlhttp.responseText + ')');

    // Process JSON
    alert("Got the info");
}else{
    alert("Ready state: "+xmlhttp.readyState);
    alert("Status: "+xmlhttp.status);
}
}

xmlhttp.open("GET", "http://www.mysite.com/search.php?"+get_variables, true);
xmlhttp.send();
Pointy
  • 405,095
  • 59
  • 585
  • 614
  • Don't use `eval`, but `JSON.parse` if you receive JSON data – Bergi Dec 05 '12 at 14:51
  • 3
    "*problem reaching the status of 200*" - What happens instead? Tell us more. What status do you get, what errors can you see in the console? Use the network inspector. – Bergi Dec 05 '12 at 14:52
  • 2
    How is the problematic computer connected to the network? What else about it is different? Can it get to other intranet sites? Are there errors reported in the console? Have you checked the network traffic directly? Can you tell at the server if the HTTP request makes it there? – Pointy Dec 05 '12 at 14:54
  • @Bergi - From the alert boxes we can tell that the readyState does reach 4, but for the status it only displays 0. We haven't checked the console yet. Guess that would have been a help, huh? We'll have to check that out and get back to you. – The Duke Of Marshall שלום Dec 05 '12 at 15:09
  • http://stackoverflow.com/questions/5005960/xmlhttprequest-status-0-responsetext-is-empty maybe? – Ian Dec 05 '12 at 15:12
  • @Pointy - The computer is connected via WiFi. Everything seems to be the same as mine. I have the exact same computer and mine works just fine. Other intranet sites work as normal. I'm not really sure how to check the server for the HTTP request. – The Duke Of Marshall שלום Dec 05 '12 at 15:12
  • Oh yeah, it's not on a local network. It's on a site in the cloud. – The Duke Of Marshall שלום Dec 05 '12 at 15:13
  • 1
    Surely the server code has an access log. You can at least monitor the TCP traffic. You can use the browser console to check the HTTP request from that end. Basically there's a *lot* of diagnostic work you need to do, because nobody out here is psychic. – Pointy Dec 05 '12 at 15:13
  • I looked on cPanel but couldn't find anything about TCP traffic or anything like that. – The Duke Of Marshall שלום Dec 05 '12 at 15:27

1 Answers1

0

Ok, I found a way to make it work.

The page with the Ajax script, the queried PHP script, and database are all on the same server. So..........

Instead of an absolute URL:

xmlhttp.open("GET", "http://www.mysite.com/search.php?"+get_variables, true);

I changed it to a relative URL:

xmlhttp.open("GET", "search.php?"+get_variables, true);

And now it's good. May not be the best way, but I haven't found any other answer or help as of yet.