You are previewing PHP jQuery Cookbook.
O'Reilly logo
PHP jQuery Cookbook

Book Description

jQuery and PHP are the dynamic duo that will allow you to build powerful web applications. This Cookbook is the easy way in with over 60 recipes covering everything from the basics to creating plugins and integrating databases.

  • Create rich and interactive web applications with PHP and jQuery

  • Debug and execute jQuery code on a live site

  • Design interactive forms and menus

  • Another title in the Packt Cookbook range, which will help you get to grips with PHP as well as jQuery

  • In Detail

    As web technology evolves, the gap between desktop applications and web applications continues to vanish. And what better way to bridge that gap, for your own website, than using the best two open source technologies in the market: PHP and jQuery. The power-combo of these two is leading the way in revolutionizing the RIA world. Although they are easy to integrate, finding or figuring out how to do what you want to do is rather arduous.

    The PHP jQuery Cookbook will be your handy guide with walkthroughs of common integration tasks and problems that will help you master the possibilities available using the PHP and jQuery combo. You will learn quick solutions to necessary tasks to integrate the power of two of the best known and most widely used web technologies of today – PHP on the server side and jQuery on the client side. Glide through the basics and move to advanced topics to create dynamic and interactive web applications with this book in hand.

    This book covers a wide array of technical aspects of creating an interactive website. Apart from basics of PHP and jQuery, you will go through advanced topics like creating plugins, validating controls, and useful utilities that you will be able to use as stand-alone tools. AJAX, the key technique of browser-server communication is covered in detail. You will also learn to use JSON, which is becoming preferred as a mode of data interchange over XML, both in web applications and web services.

    The book also covers database interaction, which is an important part of any dynamic web application. You will also gain expertise in debugging JavaScript with the help of useful tools that will save you hours of tedious manual debugging.

    Most importantly, by using jQuery and PHP together, you will be able to develop applications that are compatible with all major browsers, with no need to write code targeted at specific browsers!

    A package of comprehensive solutions to problems that may occur while building web applications with PHP and jQuery

    Table of Contents

    1. PHP jQuery Cookbook
      1. Copyright
      2. Credits
      3. About the Author
      4. About the Reviewers
      5. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      6. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      7. 1. Handling Events with jQuery
        1. Introduction
        2. Executing functions when page has loaded
          1. Getting ready
          2. How to do it...
            1. How it works...
              1. Passing a handler to .ready()
              2. Another method of using .ready()
              3. Multiple .ready() methods
          3. Binding and unbinding elements
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
              1. Binding multiple events
              2. Shortcut method for binding
              3. Triggering events
              4. Common event types
              5. Unbinding all events from an element
          4. Adding events to elements that will be created later
            1. How to do it...
            2. How it works...
              1. Removing event handlers with die()
            3. See also
          5. Submitting a form with jQuery
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
              1. Controlling form submission
            5. See also
          6. Checking for missing images
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          7. Creating the select/unselect all checkboxes functionality
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
              1. Using selectors
          8. Capturing mouse events
            1. Getting ready
            2. How to do it...
            3. How it works...
          9. Creating keyboard shortcuts
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
              1. List of common key codes
            5. See also
          10. Displaying user selected text
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
              1. Short method for getting selected text
          11. Dragging elements on a page
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
      8. 2. Combining PHP and jQuery
        1. Introduction
        2. Fetching data from PHP using jQuery
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Creating a query string automatically for all form elements
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. serializeArray() method
            2. Not all values are serialized
            3. Name should be provided to elements
          5. See also
        4. Detecting an AJAX request in PHP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Don't rely on X-Requested-With alone
        5. Sending data to PHP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Alternative method for $.post()
          5. See also
        6. Aborting AJAX requests
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Creating an empty page and loading it in parts
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Difference between load and get
          5. See also
        8. Handling errors in AJAX requests
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Parameters passed to error callback
            2. The ajaxError() method
          5. See also
        9. Preventing browser from caching AJAX requests
          1. How to do it...
            1. How it works...
            2. There's more...
              1. Only GET requests are cached
            3. See also
          2. Loading JavaScript on demand to reduce page load time
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
              1. Alternative method for getScript
            5. See also
      9. 3. Working with XML Documents
        1. Introduction
        2. Loading XML from files and strings using SimpleXML
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Parameters for simplexml_load_file
            2. simplexml_load_string
            3. Using SimpleXMLElement to create an object
            4. More info about SimpleXML and libxml
          5. See also
        3. Accessing elements and attributes using SimpleXML
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Modifying an XML with SimpleXML
            2. Adding elements to an XML
          5. See also
        4. Searching elements using XPath
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. More info about XPath
          5. See also
        5. Reading an XML using DOM extension
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Getting child nodes
            2. nodeType, nodeName, and nodeValue
          5. See also
        6. Creating an XML using DOM extension
          1. Getting ready
          2. How to do it…
            1. How it works...
            2. See also
          3. Modifying an XML using DOM extension
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
              1. Deleting nodes
            5. See also
          4. Parsing XML with jQuery
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
              1. The delegate() method
            5. See also
      10. 4. Working with JSON
        1. Introduction
        2. Creating JSON in PHP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Predefined constants
          5. See also
        3. Reading JSON in PHP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Catching JSON parsing errors
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Accessing data from a JSON in jQuery
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Other AJAX methods for requesting JSON data
            2. Handling errors while requesting JSON
            3. Parsing a JSON
          5. See also
      11. 5. Working with Forms
        1. Introduction
        2. Adding input fields dynamically in a form
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Getting values on server side
        3. Searching for user-inputted string in a page
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Search and replace
        4. Checking for empty fields using jQuery
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Validating fields one by one
          4. See also
        5. Validating numbers using jQuery
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. See also
          3. Validating e-mail and website addresses using regular expressions
            1. Getting ready
            2. How to do it...
              1. How it works...
              2. There's more...
                1. References for regular expressions
              3. See also
            3. Displaying errors as user types: Performing live validation
              1. Getting ready
              2. How to do it…
              3. How it works...
              4. See also
            4. Strengthening validation: validating again in PHP
              1. Getting ready
              2. How to do it...
              3. How it works...
              4. There's more...
                1. List of Validate filters
                2. Sanitizing data
              5. See also
            5. Creating a voting system
              1. Getting ready
              2. How to do it...
              3. How it works...
              4. There's more...
                1. Cookie expiration time
              5. See also
            6. Allowing HTML inside text areas and limiting HTML tags that can be used
              1. Getting ready
              2. How to do it...
              3. How it works...
              4. There's more...
                1. PHP tags are stripped too
      12. 6. Adding Visual Effects to Forms
        1. Introduction
        2. Creating a Tic-Tac-Toe game with effects
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Exercise—checking for a draw
        3. Informing a user while an AJAX request is in progress
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Using text instead of images
            2. Using overlays to stop a user from interacting with the form
          5. See also
        4. Creating expandable and collapsible boxes (accordion)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Using different markup for accordion
        5. Fading an element after updating it
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Floating box on demand
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Important note about animate
        7. Updating items in a shopping cart
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Removing items from the cart
          5. See also
      13. 7. Creating Cool Navigation Menus
        1. Introduction
        2. Creating a basic drop-down menu
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Opening menus on click
          5. See also
        3. Creating a menu that changes background on mouse-over
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Creating an accordion style menu
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. jQueryUI Accordion
          5. See also
        5. Creating a floating menu
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Creating an interface for tabbed navigation
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Adding more tabs
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Displaying new tab by default
          5. See also
        8. Creating a wizard using tabs
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      14. 8. Data Binding with PHP and jQuery
        1. Introduction
        2. Fetching data from a database and displaying it in a table format
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. What is a constructor?
        3. Collecting data from a form and saving to a database
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. real_escape_string() function
            2. Return values for mysqli->query()
          5. See also
        4. Filling chained combo boxes that depend upon each other
          1. Getting ready
            1. How to do it...
            2. How it works...
          2. Checking username availability from database
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. There's more...
              1. Alternative methods for implementation
          3. Paginating data for large record sets
            1. Getting ready
            2. How to do it...
            3. How it works...
          4. Adding auto-suggest functionality to a textbox
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
          5. Creating a tag cloud
            1. Getting ready
            2. How to do it...
            3. How it works...
            4. See also
      15. 9. Enhancing your Site with PHP and jQuery
        1. Introduction
        2. Sending cross-domain requests using server proxy
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Making cross-domain requests with jQuery
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. About JSONP
          5. See also
        4. Creating an endless scrolling page
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Loading data from other sources
        5. Creating a jQuery plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Displaying RSS feeds with jQuery and PHP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      16. A. Firebug
        1. Introduction
        2. Inspecting elements
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Plugins for firebug
            2. See also
          4. Editing HTML and CSS
            1. How to do it...
            2. There's more...
              1. Changing style for a specific element
          5. Debugging JavaScript
            1. How to do it...
            2. There's more...
              1. Debugging in a nutshell
              2. Inspecting AJAX requests
              3. Web developer toolbar