Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
tonyscarpelli

Ajax Worked Last Week, Now It Doesn'T

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I want to make a joke about the bug monster here, but I'm way to mature... :P

 

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.

  • Upvote 1

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...