RickH Posted September 16, 2013 Share Posted September 16, 2013 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 More sharing options...
Larry Posted September 17, 2013 Share Posted September 17, 2013 I'll check this out and get back to you (don't have the book with me right now). Link to comment Share on other sites More sharing options...
RickH Posted September 18, 2013 Author Share Posted September 18, 2013 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 More sharing options...
Larry Posted September 20, 2013 Share Posted September 20, 2013 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 More sharing options...
Recommended Posts