Book Image

Learning jQuery - Fourth Edition - Fourth Edition

Book Image

Learning jQuery - Fourth Edition - Fourth Edition

Overview of this book

To build interesting, interactive sites, developers are turning to JavaScript libraries such as jQuery to automate common tasks and simplify complicated ones. Because many web developers have more experience with HTML and CSS than with JavaScript, the library's design lends itself to a quick start for designers with little programming experience. Experienced programmers will also be aided by its conceptual consistency. LearningjQuery - Fourth Edition is revised and updated version of jQuery. You will learn the basics of jQuery for adding interactions and animations to your pages. Even if previous attempts at writing JavaScript have left you baffled, this book will guide you past the pitfalls associated with AJAX, events, effects, and advanced JavaScript language features. Starting with an introduction to jQuery, you will first be shown how to write a functioning jQuery program in just three lines of code. Learn how to add impact to your actions through a set of simple visual effects and to create, copy, reassemble, and embellish content using jQuery's DOM modification methods. The book will take you through many detailed, real-world examples, and even equip you to extend the jQuery library itself with your own plug-ins.
Table of Contents (24 chapters)
Learning jQuery Fourth Edition
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Ajax methods


We can retrieve information from the server without requiring a page refresh by calling one of these Ajax methods. Ajax methods are discussed in detail in Chapter 6, Sending Data with Ajax.

Issuing requests

Ajax method

Description

$.ajax([url], options)

Makes an Ajax request using the provided set of options. This is a low-level method that is often called via other convenience methods.

.load(url, [data], [callback])

Makes an Ajax request to url and places the response into the matched elements.

$.get(url, [data], [callback], [returnType])

Makes an Ajax request to url using the GET method.

$.getJSON(url, [data], [callback])

Makes an Ajax request to url, interpreting the response as a JSON data structure.

$.getScript(url, [callback])

Makes an Ajax request to url, executing the response as JavaScript.

$.post(url, [data], [callback], [returnType])

Makes an Ajax request to url using the POST method.

Request monitoring

Ajax method

Description

.ajaxComplete(handler)

Binds handler to be called when any Ajax transaction completes.

.ajaxError(handler)

Binds handler to be called when any Ajax transaction completes with an error.

.ajaxSend(handler)

Binds handler to be called when any Ajax transaction begins.

.ajaxStart(handler)

Binds handler to be called when any Ajax transaction begins, and no others are active.

.ajaxStop(handler)

Binds handler to be called when any Ajax transaction ends, and no others are still active.

.ajaxSuccess(handler)

Binds handler to be called when any Ajax transaction completes successfully.

Configuration

Ajax method

Description

$.ajaxSetup(options)

Sets default options for all subsequent Ajax transactions.

$.ajaxPrefilter([dataTypes], handler)

Modifies the options on each Ajax request before it is processed by $.ajax().

$.ajaxTransport(transportFunction)

Defines a new transport mechanism for Ajax transactions.

Utilities

Ajax method

Description

.serialize()

Encodes the values of a set of form controls into a query string.

.serializeArray()

Encodes the values of a set of form controls into a JavaScript data structure.

$.param(obj)

Encodes an arbitrary object of key-value pairs into a query string.

$.globalEval(code)

Evaluates the given JavaScript string in the global context.

$.parseJSON(json)

Converts the given JSON string into a JavaScript object.

$.parseXML(xml)

Converts the given XML string into an XML document.

$.parseHTML(html)

Converts the given HTML string into a set of DOM elements.