tonyscarpelli Posted August 22, 2012 Share Posted August 22, 2012 I used the Chapter 11 book code last week in Xampp after installing Xampp and it worked. This week I tried it out and it didn't work. I rebooted and removed IIS which was on my computer, but that didn't work either. After doing a bit of debugging, it turned out that the Ajax status code was 0. I changed the test.js code so that it worked with a status = 0 ( || (ajax.status == 0) ). And now it works again. So what whould make the status code turn into 0 from last week? Or, in other words, what makes the ajax status equal 0 to begin with? Confusing... Thanks. Link to comment Share on other sites More sharing options...
sonal Posted August 22, 2012 Share Posted August 22, 2012 It is necessary to run your ajax script through a server. Larry has explained it like this, "If your request is returning a 0 status code, you probably are not making the request through a URL. I hope that's what where the problem is coming from in your case... Link to comment Share on other sites More sharing options...
HartleySan Posted August 22, 2012 Share Posted August 22, 2012 If you're not making a request through a URL (for example, you're using Ajax to load a local text file), you do not need the ajax.status condition. Just remove it entirely, keeping only the ajax.readyState === 4 condition, and you should be fine. Link to comment Share on other sites More sharing options...
Antonio Conte Posted August 23, 2012 Share Posted August 23, 2012 I want to make a joke about the bug monster here, but I'm way to mature... Just to contribute a little bit, a lot of bugs occur because your logical checks are not strong enough. Notice how Jon used "ajax.readyState === 4" here? The last equal sign tells JS to perform a test on type too. It's those sort of things you need to be careful about. A lot of PHP functions might also return a VALUE equal to false, true or null. That's why you see some of the documentation tells you to use the === check for those. Both PHP and JS are weakly typed, so it's our job to make sure we get the type right. 1 Link to comment Share on other sites More sharing options...
tonyscarpelli Posted August 23, 2012 Author Share Posted August 23, 2012 The code is in the Xampp server on my machine. Isn't that supposed to work? If it doesn't, then Xammp is not working. I am running the code from within NoteTab which calls the browser with the URL of the server. Maybe that is how I shouldn't be doing it? I'll try putting it on my web site and see how that works. Thanks. Link to comment Share on other sites More sharing options...
HartleySan Posted August 23, 2012 Share Posted August 23, 2012 Probably wouldn't hurt to just upload it to your hosted server first, as you can more easily confirm things from there. If you use XAMPP, make sure the Apache server is running as well as MySQL (if necessary), put the files somewhere under the htdocs folder, and then run it through localhost in the URL in your browser. Link to comment Share on other sites More sharing options...
Recommended Posts