Jump to content
Larry Ullman's Book Forums

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


 Share

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

Link to comment
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

Link to comment
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?

Link to comment
Share on other sites

 Share

×
×
  • Create New...