Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

CHAPTER 14: Using Ajax: Part I > Summary - Pg. 428

CHAPTER 14 USING AJAX: PART I </div> </div> <div id="buttonDiv"><button type="submit">Place Order</button></div> </form> </body> </html> In this example, I have added the jquery.form.js script file to the document (this is included in the download for the plugin) and, in the script element, called the ajaxForm method on the form element. The argument to the ajaxForm method is a callback function, and this provides me with access to the response from the server. This is a neat and simple approach to basic Ajax forms, right down to the fact that the URL to post the form to is taken from the form element itself. This plugin does a lot more, and it even includes some support for basic form validation, but if you get to the point where you want to start taking control of your Ajax requests, then I suggest using the low-level Ajax features that I describe in Chapter 15. But for quick and simple situations, this plugin is convenient and well-designed. Summary In this chapter, I introduced you to the shorthand and convenience methods that jQuery provides for Ajax. I have shown you how to use the get and post methods to make asynchronous HTTP GET and POST requests, how to work with JSON data, and how to use the convenience methods that deal with specific data types. Along the way, I have shown you the most common Ajax pitfall, explained cross-origin requests, and showed how to deal with them and briefly introduced a jQuery plugin, which makes it even easier to use Ajax with forms that the shorthand methods. In the next chapter, I'll show you the