(Ebook) PHP jQuery Cookbook: over 60 simple but highly effective recipes to create interactive web applications using PHP with jQuery by Vijay Joshi ISBN 9781621988977, 9781849512749, 9781849512756, 162198897X, 1849512744, 1849512752 pdf download
(Ebook) PHP jQuery Cookbook: over 60 simple but highly effective recipes to create interactive web applications using PHP with jQuery by Vijay Joshi ISBN 9781621988977, 9781849512749, 9781849512756, 162198897X, 1849512744, 1849512752 pdf download
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312
https://ebooknice.com/product/sat-ii-success-math-1c-and-2c-2002-peterson-
s-sat-ii-success-1722018
(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master the SAT
Subject Test: Math Levels 1 & 2) by Arco ISBN 9780768923049,
0768923042
https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-arco-
master-the-sat-subject-test-math-levels-1-2-2326094
(Ebook) Cambridge IGCSE and O Level History Workbook 2C - Depth
Study: the United States, 1919-41 2nd Edition by Benjamin
Harrison ISBN 9781398375147, 9781398375048, 1398375144,
1398375047
https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044
https://ebooknice.com/product/beginning-jquery-2-for-asp-net-developers-
using-jquery-2-with-asp-net-web-forms-and-asp-net-mvc-4634656
https://ebooknice.com/product/pro-php-and-jquery-2090250
(Ebook) Learning PHP, MySQL & JavaScript - With jQuery, CSS &
HTML5 by Robin Nixon ISBN 9781491978917, 1491978910
https://ebooknice.com/product/learning-php-mysql-javascript-with-jquery-
css-html5-7294746
https://ebooknice.com/product/master-web-design-with-html-css-javascript-
and-jquery-create-stunning-interactive-websites-55101262
PHP jQuery Cookbook
Vijay Joshi
BIRMINGHAM - MUMBAI
PHP jQuery Cookbook
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly or
indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies
and products mentioned in this book by the appropriate use of capitals. However, Packt
Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-849512-74-9
www.packtpub.com
Vijay Joshi is a programmer with over six years of experience on various platforms. He
discovered his passion for open source four years ago when he started playing with PHP on a
hobby project after completing his Masters in Computer Applications. Vijay is a professional
web developer now and prefers writing code ONLY in open source (but that does
not always happen, unfortunately!). He switches hats as needed—he is full-time lead
programmer at Philogy, independent consultant for a few selected companies where he
advises them on a variety of Internet-based initiatives, and still remains an active blogger
at http://vijayjoshi.org.
Besides his work, he enjoys reading, trekking, and sometimes getting obsessed with fitness.
Writing a book is a long and complicated task which requires the support
and coordination of many people. I am thankful to the entire team at Packt,
especially Michelle, Chaitanya, and Neha for being so cooperative and
patient with me.
Md. Mahmud Ahsan graduated in Computer Science & Engineering from the International
Islamic University Chittagong (IIUC) in Bangladesh. He is a Zend Certified Engineer and
expert in developing web applications, Facebook applications, Mashup applications, and
iPhone-native applications. Besides his full time job, he blogs at http://thinkdiff.net
and writes articles on different technologies, especially Facebook applications development.
He lives in Bangladesh with his wife Jinat.
Currently, Mahmud works as a Software Engineer (remote developer) in i2we inc. (867 Avalon,
Lafayette, CA) where he develops social web applications using PHP, MySQL, JavaScript, Zend
Framework, CodeIgniter, jQuery, and Mashup APIs. He also leads various small to medium
level projects.
Mahmud is also an Indie iPhone application developer and publishes his own applications at
http://ithinkdiff.net.
He was a technical reviewer of the Zend Framework 1.8 Web Application Development
book by Packt Publishing.
I’m very grateful to my father who bought a computer for me in 2001. Since
then, I have loved programming and working with various technologies.
Joe Wu is a full-time Senior PHP Web Developer, and has been in the industry since 2005.
He has worked on various projects of all sizes and is familiar with most of the open source
technologies surrounding PHP web development.
Joe is always enthusiastic about new and upcoming technologies and is keen to learn and
pick up new skill-sets wherever possible and utilize them in his current or future projects. He
is also keen to learn about new opportunities and innovative ideas out there, and believes
that the market is always wide open for new and upcoming innovations to improve our way
of living.
Aside from all the technological computer work, Joe is a professional badminton player and
manages to somehow fit a near full-time training schedule together with his full-time job. Joe's
best ranking of 59th in the world in singles and the attendance of the Commonwealth Games
Delhi 2010 means that he has equally as much experience in badminton and web developing.
Aside from all the endeavors, Joe also works for his own company (with his business partner)
to put his skills and experience to good use and to help anyone who needs assistance with
web development.
Shameemah Kurzawa has been programming since she was at high school. Being
motivated to be a Systems Analyst, she pursued both undergraduate and postgraduate
studies in Business Information System and Software Engineering, respectively.
She has been working as a Web Developer/Analyst for the past five years, for a renowned
company SBS (Special Broadcasting Service) in Australia. Besides work, she enjoys spending
her time with her family (she is the mum of a little two year old baby boy) and enjoys travelling
as well as investigating new technologies.
I would like to thank my husband, my son, and the Packt Publishing team for
their support and understanding in reviewing this book.
www.PacktPub.com
At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books
and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt’s online digital book
library. Here, you can access, read and search across Packt’s entire library of books.
Why Subscribe?
Fully searchable across every book published by Packt
Copy & paste, print and bookmark content
On demand and accessible via web browser
ii
Table of Contents
iii
Preface
Nowadays, web applications are behaving more and more like desktop applications with
lesser page loads and more user interaction and effects. The Web has become faster and
applications such as Gmail and Facebook have given a new meaning to web applications.
PHP on the server side and jQuery on the client side (browser) are a killer combination for
developing interactive web applications. PHP is the leading language of choice among web
developers and jQuery is now used on more than one-third of the top 1000 sites on the
internet and is the most widely-used library.
One thing that PHP and jQuery have in common is that they are easy to learn. Once you know
the basics, you can promote yourself to the next level easily.
And this is what the book will do for you. It is like a toolbox having a myriad of tools inside.
It will allow you to write faster web applications, which feel like desktop applications, with
the help of PHP and jQuery. Whether you want to learn live validations, create plugins, drag
elements, create a menu, watch videos using YouTube API, or interact with the database, just
jump to the respective recipe for the solution. AJAX, a key feature of rich internet applications,
is also covered in detail.
You are not required to read this book from the beginning to the end. Each recipe is
independent and is like a "how to" or a mini application in itself. You can directly look
for a solution to a specific problem.
I hope you will find this book useful and that it will help you to take your skills to a higher level.
Chapter 2, Combining PHP and jQuery, lists several ways of sending AJAX requests using
jQuery and also describes how PHP responds to such requests. This chapter also contains
recipes that deal with caching of AJAX requests and error handling during AJAX requests.
Preface
Chapter 3, Working with XML Documents, explains working with XML files in PHP as well as
jQuery. Recipes will describe how to read, write, and modify XMLs using DOM and SimpleXML
extensions of PHP. Parsing XML with jQuery is also discussed.
Chapter 4, Working with JSON, discusses JSON in detail. You will be shown how to read and
write JSON data in PHP, and also explore jQuery's inbuilt capabilities of parsing JSON.
Chapter 5, Working with Forms, deals with forms and form validations. You will learn how to
validate forms for different types of data with jQuery. This will cover validating empty fields,
numbers, e-mail addresses, web addresses, and much more. Server-side validation methods
will also be discussed to make validations more powerful.
Chapter 6, Adding Visual Effects to Forms, extends the previous chapter and provides recipes
for adding visual effects to forms. Recipes in this chapter allow you to create user-friendly
forms by adding effects, such as highlighting, fading, expandable boxes, and various others.
Chapter 7, Creating Cool Navigation Menus, describes the creation of different types of
menus, such as animated menus, accordions, and tabbed menus. Advanced techniques for
creating tabs are also covered that will guide you in adding and removing tabs on the fly.
Chapter 8, Data Binding with PHP and jQuery, explains, in detail, how a database can be used
along with PHP and jQuery. Examples included in this chapter will explain how to fetch data
from the database and use it in web forms.
Chapter 9, Enhancing your Site with PHP and jQuery, teaches you some advanced techniques
of PHP and jQuery. It will show how to overcome browser restrictions like
cross-domain requests. You will learn to create a jQuery plugin for custom use and an
endless scrolling page among other things.
Appendix, Firebug, explains the use of Firebug for debugging HTML and JavaScript in web
pages. You will learn how to edit HTML and change the appearance of pages on the browser
itself without switching to actual code files. You will be able to execute JavaScript directly from
Firebug and further understand debugging JavaScript using this add-on.
In terms of technical proficiency, this book assumes that you have working knowledge of PHP,
jQuery, HTML, and CSS. You need to know only the basics of these, leave the rest to this book.
Preface
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of
information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "The input button has also been attached
to a click event."
New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "Now click on the Create
New Element button a few times to create some DIV elements".
Preface
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or may have disliked. Reader feedback is important for us to develop
titles that you really get the most out of.
If there is a book that you need and would like to see us publish, please send us a note in the
SUGGEST A TITLE form on www.packtpub.com or e-mail suggest@packtpub.com.
If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you
to get the most from your purchase.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen.
If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be
grateful if you would report this to us. By doing so, you can save other readers from frustration
and help us improve subsequent versions of this book. If you find any errata, please report them
by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata
submission form link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded on our website, or added to any list
of existing errata, under the Errata section of that title. Any existing errata can be viewed
by selecting your title from http://www.packtpub.com/support.
Preface
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt,
we take the protection of our copyright and licenses very seriously. If you come across any
illegal copies of our works, in any form, on the Internet, please provide us with the location
address or website name immediately so that we can pursue a remedy.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.
Questions
You can contact us at questions@packtpub.com if you are having a problem with any
aspect of the book, and we will do our best to address it.
Handling Events with
1
jQuery
In this chapter, we will cover:
Introduction
Events are actions that execute some JavaScript code for producing the desired result. They
can be either some sort of manipulation of a document or some internal calculations.
Since different browsers handle events differently, it takes a lot of effort to write JavaScript
code that is compatible with all browsers. This chapter will help you understand event
handling and explore related methods of jQuery that can make scripts compatible on different
browsers. You will learn to work with the keyboard and mouse events. Advanced event
handling topics like dragging and keyboard shortcuts are also discussed.
Random documents with unrelated
content Scribd suggests to you:
in getting the lowest figures for his road, and the large amount of
his purchases enables him to secure the best rates. And last, but not
least, in matters where dishonesty would find so great opportunities,
it is safer to concentrate responsibility than to diffuse it.
As I shall not again refer to this department, what remains of
interest for me to say about it will be said here. As an adjunct to it,
storehouses are established at central points in which stocks of
articles in ordinary use are kept on hand. Whenever supplies are
wanted in any other department—as, for instance, a bell-cord and
lantern by a conductor—requisitions are presented, approved by a
designated superior. These requisitions state whether the articles are
to be charged to legitimate wear and tear, and if so, whether to the
passenger or the freight service, and of which subdivision of the
road; or whether they are to be charged to the conductor for other
articles not properly accounted for. Without going into further detail,
it can be readily seen how the comptroller's office can, at the end of
each month, from these requisitions, have a complete check upon all
persons responsible for the care of property. The purchasing agent,
too, from his familiarity with prices, is usually charged with the sale
of all condemned and worn-out material.[14]
Before returning to a more detailed review of the operating
departments of a railroad, its legal department requires a few words.
Not only is a railroad corporation, being itself a creation of the law,
peculiarly bound to conform all its actions to legal forms and tenets,
but it is also a favorite target for litigation. The popular prejudice
against corporations, it may be said in passing, is utterly illogical.
The corporation is the poor man's opportunity. Without it he could
never share in the gains and advantages open to capital in large
sums. With it a thousand men, contributing a thousand dollars each,
compete on equal terms with the millionaire. Its doors are always
open to any who may wish to share its privileges or its prosperity,
and no man is denied equal participation according to his means and
inclinations. It is the greatest "anti-poverty" invention which has ever
been produced, and the most democratic. But, for all that, instead of
possessing the unbounded power usually ascribed to it, no creature
of God or man is so helpless as a corporation before the so-called
great tribunal of justice, the American jury. It may not be literally
true that a Texas jury gave damages to a tramp against a certain
railroad because a section-master's wife gave him a meal which
disagreed with him, but the story can be nearly paralleled from the
experience of many railroads. Hence settlements outside of the law
are always preferred where they are at all possible, and an essential
part of an efficient legal organization is a suitable man always ready
to repair promptly to the scene of any loss or accident, to examine
the circumstances with the eye of a legal expert on liabilities.
But the management of claims, and of loss and damage suits,
though a large part, is by no means all of the legal business
connected with a railroad. Every contract or agreement should pass
under scrutiny of counsel, and in the preparation of the various
forms of bonds, mortgages, debentures, preferred stocks, etc.,
which the wants of the day have brought forth, the highest legal
talent finds employment. For, as development has multiplied the
types of cars and engines to meet special wants, so have a great
variety of securities been developed to meet the taste and prejudices
of investors of all nations. There is, in fact, a certain fashion in the
forms of bonds, and the conditions incorporated in mortgages, which
has to be observed to adapt any bond to its proposed market.
We shall now
return to the
operating
departments
under their
respective
heads, and
glance briefly at
the methods
and detail
pursued in
each. On roads
of large mileage the general manager is assisted by general or
division superintendents in charge of roadway, motive power, and
trains of one or more separate divisions; but for our purposes we
may consider the different departments without reference to these
superintendents.
A. Number of Engine.
B. Passenger
C. Freight.
D. Gravel or Construction.
E. Switching.
F. Total.
G. Eighth Cords of wood.
H. Bushels Coal.
I. Cost of Fuel.
[Table—Part 1 of 4]
A. B. C. D. E. F. G. H. I.
A. J. K. L. M. N. O. P. Q.
Cost of Repairs.
A. R. S. T. U. V. W. X.
$ $ $ $
1 $ 87.64 $ 66.32 $ 289.72
1,293.80 115.00 223.40 2,876.41
2 106.85 1,646.90 82.50 69.65 75.14 144.79 3,112.81
3 93.85 1,489.65 187.50 178.25 63.61 241.86 3,113.94
4 171.85 1,719.55 212.50 203.95 100.13 304.08 3,620.18
5 144.86 1,628.80 202.00 240.55 114.98 355.53 3,666.50
6 173.92 1,884.50 10.00 172.35 63.65 236.00 3,346.68
8 97.34 1,593.05 150.00 110.75 106.69 217.44 3,414.13
9 108.53 1,625.80 200.00 139.80 175.48 315.28 3,918.02
10 108.38 1,669.55 205.00 207.55 109.78 317.33 4,041.93
11 111.83 1,126.75 5.00 413.95 89.76 503.71 2,558.29
12 106.31 1,405.10 25.00 37.45 27.17 64.62 2,519.78
30 142.71 1,719.56 212.50 144.50 77.52 222.02 4,118.15
31 152.16 1,554.55 205.00 642.50 432.86 1,075.36 4,703.66
32 108.40 1,186.40 172.00 1,729.70 438.40 2,168.10 4,752.00
34 108.40 1,186.40 137.00 1,522.10 781.64 2,303.74 4,313.48
1,823.80 22,603.45 2,121.00 6,036.45 2,723.13 8,759.58 54,075.96
A. Number of Engine.
Y. Bushel Coal.
Z. Gal. Engine Oil.
AA. Pound of Tallow.
BB. Repairs.
CC. Fuel.
DD. Stores.
EE. Wages E. and F.
FF. Cleaning.
GG. Total.
HH. Car Mileage.
[Table—Part 4 of 4]
1 1.5 122.3 34.5 01.76 06.64 00.53 07.89 00.61 17.43 177,659
2 1.1 126.8 27.7 00.94 07.34 00.69 10.69 00.53 20.19 197,203
3 0.9 77.7 17.4 02.32 10.58 00.90 14.31 02.04 30.15 182,402
4 2.7 127.2 32.8 00.92 03.69 05.23 05.24 00.64 15.72 139,422
5 2.5 128.2 41.2 01.08 04.06 00.44 04.96 00.61 11.15 135,780
6 3.1 140.4 36.3 00.72 03.22 00.53 05.82 00.03 10.32 —
8 1.5 147.8 37.9 01.09 06.84 00.49 08.04 00.76 17.22 305,024
9 1.4 150.0 48.5 01.30 06.88 00.40 06.70 00.82 16.10 383,682
10 1.5 195.4 46.5 01.23 06.77 00.31 06.49 00.79 15.59 409,035
11 3.0 173.6 36.4 02.13 03.43 00.47 04.77 00.02 10.82 —
12 2.0 171.0 23.5 00.36 05.11 00.59 07.82 00.14 14.02 66,834
30 2.3 185.4 74.9 00.53 04.40 00.34 04.15 00.51 09.93 231,554
31 2.2 154.1 50.8 02.87 04.58 00.40 04.15 00.54 12.54 202,289
32 1.6 129.5 31.2 12.11 06.25 00.60 06.64 00.96 26.56 184,083
34 3.2 108.5 35.5 11.41 03.48 00.54 05.29 00.67 21.39 107,060
2.5 148.1 38.5 02.31 04.98 00.48 05.97 00.55 14.29 2,722,027
The master car-builder has charge of the shops where cars are
built and repaired, and of the car-inspectors who are stationed at
central and junction points to prevent defective cars being put into
the trains.
Formerly each railroad used its own cars exclusively, and through
freights were transferred at every junction point. This involved such
delay and expense that railroads now generally permit all loaded
cars to go through to destination without transfer, and allow each
other a certain sum for the use of cars. Usually this is about three-
quarters of a cent for each mile which the car travels on a foreign
road. This involves a great scattering of cars, and an extensive
organization to keep record of their whereabouts and of the
accounts between the companies for mileage.[15] This organization
will be referred to more fully in connection with the department of
transportation. But the joint use of each other's cars makes it
necessary that there should be at least enough similarity in their
construction and their coupling appliances to permit their
indiscriminate use upon all roads. And conventions of master car-
builders have recommended certain forms and dimensions as
standards, which are now in general use.
There is much convenience in this, but one disadvantage. It
requires almost unanimous action to introduce any change of form
or of construction, however advantageous it may be. And to secure
unanimous action in such matters is almost as hard as it would be to
secure unanimity in a change in the spelling of English words. Still
there is progress, though slow, toward several desirable reforms, the
most important of which is the adoption of a standard automatic
coupler (see p. 142).
Having shown how the property of all kinds is kept in efficient
condition, we next come to its operation. This is called "conducting
transportation," and the officer in charge is usually called the
superintendent of transportation. All train-despatchers, conductors,
train-men, and telegraph operators are under his immediate control.
He makes all schedules and provides all extra and irregular service
that the traffic department makes requisition for, himself calling upon
the superintendent of machinery for the necessary locomotives,
switching engines, and cars. It is his especial province to handle all
trains as swiftly as possible, and to see that there are no collisions.
It is impossible to detail fully the safeguards and precautions used to
this end, but the general principles observed are as follows:
First, a general time-table or schedule is carefully made out for all
regular trains upon each division, showing on one sheet the time of
each train at each station.
This schedule is all that is needed so long as all trains are able to
keep on time, and there are no extras. Trouble begins when regular
trains cannot keep on schedule, or when extra trains have to be sent
out, not provided for on the schedule. A diagram, or graphic
representation of this schedule, upon a board or large sheet of
paper, is an important feature of the office regulating train-
movements. Twenty-four vertical lines divide the board into equal
spaces representing the twenty-four hours of the day, numbered
from midnight to midnight. Horizontal lines at proportionate
distances from the top represent the stations in their order between
the termini, represented by the top and bottom lines of the diagram.
The course of every train can now be plotted on this diagram in an
oblique line joining the points on each station line corresponding to
the time the train arrives at and leaves that station. The cut on the
opposite page will illustrate. It represents a road 130 miles long from
A to N, with intermediate stations B, C, D, etc., at different distances
from each other, and six trains are shown as follows:
A passenger train, No. 1, leaving A at 12 midnight and arriving at
N at 4.05 A.M. A fast express, No. 2, leaving N at 12.45 and arriving
at A at 3.30. A local passenger train, No. 4, which leaves N at 1.15,
runs to E by 4 A.M., stops there until 4.10, and returns to N by 7 A.M.;
being called No. 3 on the return, as the direction is always indicated
by the train-number's being odd or even. No. 5 is a way freight,
leaving A at 12.05 and making long stops at each station. No. 6 is an
opposing train of the same character.
Diagram Used in Making Railway Time-Tables.
So it was delivered to No. 1, and that train left "H" at full speed,
expecting to run thirty-five miles to "K" before meeting No. 2. There
was no telegraph office at "I," and there were no passengers to get
off or on, and it passed there without stopping, and three miles
below ran into No. 2 on a curve.
By one of those strange impulses which seem to come from some
unconscious cerebration, the train-despatcher meanwhile had a
feeling that something was wrong, and looked again at the message
received from "H" and discovered his mistake. But the trains were
then out of reach. He still hoped that No. 2 might arrive at "I" first,
or that they might meet upon a straight portion of road, and as the
time passed he waited at the instrument in a state of suspense
which may be imagined. When the news came he left the office, and
never returned.
Double tracks make accidents of this character impossible; but
introduce a new possibility, that a derailment from any cause upon
one track may obstruct the other track so closely ahead of an
opposing train that no warning can be given.
Central Switch and Signal Tower.
A B C
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com