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

Chapter 11 - Handling Of Error Is To Do It Again?

Recommended Posts

I've been working through the book and really enjoying it.

 

I'm thrown by the Contact Form example in the Ajax chapter.  What it seems to be doing seems stupid, so I'm wondering whether I'm misunderstanding.

 

The handleAjaxRequest function is defined on p. 458.  It seems to specify that in case of an error, we submit the form again.  The anonymous function that is called if the user clicks the submit button is defined on p. 459.  It sends the Ajax request to the server.

 

So if something goes wrong, we just try again?  I thought perhaps we would send the form in a non-Ajaxy way, or something?

 

                Regards, Rick

Share this post


Link to post
Share on other sites

Okay, thanks Larry.

 

The same thing happens again on pp. 576-7.  But this time you say explicitly:  "The else clause applies if the status code was not good, in which case the form will actually be submitted as if the JavaScript wasn't there."

 

I have a theory that when one calls the submit() function on a form, the form is submitted, but the submit event is not emitted.  But I don't know whether my theory is true.  Maybe something else is going on.

 

 

                     Regards, Rick

Share this post


Link to post
Share on other sites

Right, so if you see the first lines at the top of 459, it explains that if the Ajax request fails, the form will actually be submitted to the server-side resource. In other words, if the Ajax fails (or if JavaScript is disabled), the form is submitted as if there was no JavaScript at all. But if the Ajax does work, the form's regular submission will be prevented. Does that make sense?

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