From the course: Ajax with PHP: Add Dynamic Content to Websites
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Prevent default
From the course: Ajax with PHP: Add Dynamic Content to Websites
Prevent default
- [Instructor] In this movie, we'll learn how to use JavaScript to prevent default behavior from executing. Specifically, we're going to learn how we can bind our AJAX function to a submit button, but also prevent that submit button from submitting a non-AJAX request. Let me start by demonstrating the issue that we have. So in our existing AJAX form, we have two buttons, one that submits a regular HTML form, and one that submits an AJAX request. And that's useful for being able to see both of them and to try them both out. But in the real world, we wouldn't want to have that. We would want to just have one single button, and we'd want that button to function as an HTML button if the user didn't have JavaScript enabled, and we would want it to function as an AJAX button if they did. That's the idea of progressive enhancement. Let's go over here and let's just try that real quick. Let's try and make one button. Notice that the submit button has a type of submit. An AJAX button was just…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.