checkCache() function, <strong>AJAX</strong> Suggest <strong>and</strong> Autocomplete, 185 database server, 12 database tables, creating, 101 checkForChanges() function, <strong>AJAX</strong> Suggest <strong>and</strong> Autocomplete, 186 DELETE comm<strong>and</strong>, MySQL, 104 deleteMessages() function, <strong>AJAX</strong> chat, 162, 163 checkUsername() function, <strong>AJAX</strong> chat, 161 deselectAll() function, <strong>AJAX</strong> Suggest <strong>and</strong> class members, 110 Autocomplete, 185 classes, OOP, 109 destructors, OOP, 110 clearInterval() function, 91 display_errors option, php.ini, 77, 90 Client URL Library (CURL), 86 displayError() function, <strong>AJAX</strong> chat, 162 client-side technologies, 11 displayMessage() function, <strong>AJAX</strong> chat, 162 client-side validation, 122 displayMessages() function, <strong>AJAX</strong> chat, 162 code structure, <strong>PHP</strong>, 109 displayResults() function, <strong>AJAX</strong> Suggest <strong>and</strong> complete <strong>AJAX</strong> application, st<strong>and</strong>ard Autocomplete, 185 structure. See Friendly <strong>AJAX</strong> application div element, 34 connecting to remote servers. See remote servers, connecting to constructors, OOP, 110 DML comm<strong>and</strong>s, MySQL, 104 Document Object Model about, 15, 30 createPointInfo() function, realTimeChart.js, 201 client-side uses, 30 createTextRange() function, <strong>AJAX</strong> Suggest server-side uses, 30 <strong>and</strong> Autocomplete, 187 document structure, RSS, 224 createXmlHttpRequestObject() function, 43, 45 document.write comm<strong>and</strong>, 31 createXmlHttpRequestObject() function, quickstart.js, 25 DOM, 15, 30 DOM functions, <strong>PHP</strong>, 66 creating database tables, MySQL, 101 DOMDocument class, <strong>PHP</strong> DOM, 70 creating XML structures, 63 drag <strong>and</strong> drop CRssReader class, rss_reader.php, 235 <strong>AJAX</strong> sortable list application, 238 CSS, 39 shopping carts, 237 CSS <strong>and</strong> JavaScript sortable lists, 238 csstest.html, 39 DROP comm<strong>and</strong>, MySQL, 102 csstest.js, 40 styles.css, 40, 41 CURL, 86 E Emacs editor, 165 D encodeURIComponent() function, JavaScript, 141, 162 data access, remote server, 85 error h<strong>and</strong>ling data grid about, 59 config.php, 209 Firefox JavaScript console, 60 error_h<strong>and</strong>ler.php, 209 Internet Explorer, 61 grid.class.php, 207 Opera, 61 grid.css, 216 <strong>PHP</strong>, 71, 75 grid.js, 211, 219 try/catch mechanism, 60 grid.php, 206, 218 errors, <strong>PHP</strong>5, 75 grid.xsl, 210, 219 escape() function, <strong>AJAX</strong> Suggest <strong>and</strong> index.html, 210 Autocomplete, 185 Data Manipulation Language (DML), 104 Even More DOM application data manipulation, MySQL, 104 evenmorejsdom.html, 37 data type, MySQL, 102 evenmorejsdom.js, 38 database connection, 105 database preparation, <strong>AJAX</strong>, 264 database security, 105 event object, <strong>AJAX</strong> Suggest <strong>and</strong> Autocomplete, 186 events, JavaScript, 33 268 www.it-ebooks.info
exception h<strong>and</strong>ling, JavaScript, 43 Google Reader, 224 exceptions, throwing, 59 Google Suggest, 15, 166 Extensible Stylesheet Language (XSL), 203 grid. See data grid Extensible Stylesheet Language Transformation (XSLT), 203 F h<strong>and</strong>leCheckingAvailability() function, 98 h<strong>and</strong>leGettingColor() function, <strong>AJAX</strong> chat, 161 fetch_array() method, MySQL, 109 h<strong>and</strong>leGettingNumber() function, 99 FIFO structure, message queue, 125 h<strong>and</strong>leGettingResults() method, file_get_contents() function, 85, 90, 99 ajaxRequest.js, 201 Firefox JavaScript console, error h<strong>and</strong>ling, 60 h<strong>and</strong>leGettingSuggestions() function, <strong>AJAX</strong> form validation, 121 Suggest <strong>and</strong> Autocomplete, 185 form validation with <strong>AJAX</strong> h<strong>and</strong>leKey() function, <strong>AJAX</strong> chat, 162 allok.php, 130 h<strong>and</strong>leKeyUp() function, <strong>AJAX</strong> Suggest <strong>and</strong> config.php, 133 Autocomplete, 186 create table, 126 h<strong>and</strong>leOnMouseOut() function, <strong>AJAX</strong> Suggest error_h<strong>and</strong>ler.php, 133 <strong>and</strong> Autocomplete, 185 index.php, 128, 139 h<strong>and</strong>leOnMouseOver() function, <strong>AJAX</strong> index_top.php, 127, 139 Suggest <strong>and</strong> Autocomplete, 185 populate table, 126 h<strong>and</strong>leReceivingMessages() function, <strong>AJAX</strong> validate.class.php, 134, 143 chat, 162 validate.css, 126 h<strong>and</strong>leRequestStateChange() function, 54 validate.js, 131, 140 h<strong>and</strong>leRequestStateChange()method, 49 validate.php, 134 h<strong>and</strong>leResults() function, realTimeChart.js, 202 framework, repetitive asynchronous requests, 91 h<strong>and</strong>leServerResponse() function, books.js, 58 Friendly <strong>AJAX</strong> application h<strong>and</strong>leServerResponse() function, about, 109 quickstart.js, 25, 27 config.php, 111, 117 hideSuggestions() function, <strong>AJAX</strong> Suggest <strong>and</strong>, error_h<strong>and</strong>ler.php, 111, 117 friendly.class.php, 111, 116, 119 HTML, 10 friendly.css, 110, 113 HTTP, 10 friendly.js, 110, 113, 118 HTTPS, 11 friendly.php, 111, 115, 118 HyperText Markup Language, 10 index.html, 110, 112 G I imagecreatefrompng() function, <strong>AJAX</strong> chat, 163 GD library, 147 indexes, MySQL, 102 getAllResponseHeaders() method, XMLHttpRequest, 47 init() function, <strong>AJAX</strong> chat, 162 init() function, realTimeChart.js, 201 getColor() function , <strong>AJAX</strong> chat, 161 innerHTML property, DOM, 36 getFormattedXML() function, 235 input data validation, 121 getMouseXY() function, <strong>AJAX</strong> chat, 161 INSERT comm<strong>and</strong>, MySQL, 104 getResponseHeader() method, installation, Unix XMLHttpRequest, 47 Apache, 261 getSuggestions() function, <strong>AJAX</strong> Suggest <strong>and</strong> MySQL, 261 Autocomplete, 185 <strong>PHP</strong>, 262 GMail, 15 installation, Windows, 256 GNU Emacs editor, 165 Apache, 256 Google Maps, 15 H 185 269 www.it-ebooks.info
- Page 1 and 2:
www.it-ebooks.info
- Page 3 and 4:
AJAX and PHP Building Responsive We
- Page 5 and 6:
About the Authors Cristian Darie is
- Page 7 and 8:
About the Reviewers Emilian Balanes
- Page 9 and 10:
Table of Contents Preface 1 Chapter
- Page 11 and 12:
Table of Contents Chapter 6: AJAX S
- Page 13 and 14:
Preface AJAX is a complex phenomeno
- Page 15 and 16:
Preface What You Need for This Book
- Page 17 and 18:
Preface Errata Although we have tak
- Page 19 and 20:
1 AJAX and the Future of Web Applic
- Page 21 and 22:
Chapter 1 Because end-user satisfac
- Page 23 and 24:
Chapter 1 Three points for you to k
- Page 25 and 26:
Chapter 1 With JavaScript, develope
- Page 27 and 28:
interrupting the user from his or h
- Page 29 and 30:
• Creating simple online chat sol
- Page 31 and 32:
Chapter 1 done typing. (This method
- Page 33 and 34:
Chapter 1 All exercises from this b
- Page 35 and 36:
etrieve the user name $name = $_GET
- Page 37 and 38:
Chapter 1 If you're curious to test
- Page 39 and 40:
Chapter 1 request. In our case, thi
- Page 41 and 42:
2 Client-Side Techniques with Smart
- Page 43 and 44:
AJAX Foundations: JavaScript and
- Page 45 and 46:
Chapter 2 • Because there is no s
- Page 47 and 48:
Time for Action—Using JavaScript
- Page 49 and 50:
Even More DOM In the previous exerc
- Page 51 and 52:
Chapter 2 What Just Happened? Well,
- Page 53 and 54:
Chapter 2 font-size: 10pt; } .Table
- Page 55 and 56:
Chapter 2 Creating the XMLHttpReque
- Page 57 and 58:
Chapter 2 You could, for example, c
- Page 59 and 60:
You will learn the most interesting
- Page 61 and 62:
Chapter 2 The safer version of proc
- Page 63 and 64:
Chapter 2 4. Create a file call
- Page 65 and 66:
Chapter 2 Figure 2.6: The Four HTTP
- Page 67 and 68:
Chapter 2 } } else { // display sta
- Page 69 and 70:
Chapter 2 } { // try to create XMLH
- Page 71 and 72:
Chapter 2 The responseXML method of
- Page 73 and 74:
Chapter 2 Figure 2.10: Opera Displa
- Page 75 and 76:
I admit that the following piece of
- Page 77 and 78:
3 Server-Side Techniques with PHP a
- Page 79 and 80:
Chapter 3 } for (var i=0; i
- Page 81 and 82:
Chapter 3 // create the element $b
- Page 83 and 84:
Chapter 3 // create the root eleme
- Page 85 and 86:
Chapter 3 // read a file from the s
- Page 87 and 88:
Chapter 3 Figure 3.3: PHP Parameter
- Page 89 and 90:
Chapter 3 Without the customized er
- Page 91 and 92:
} } // display the error in case of
- Page 93 and 94:
Chapter 3 Figure 3.7: Connecting to
- Page 95 and 96:
Chapter 3 } } // continue only if H
- Page 97 and 98:
Chapter 3 You can make Firefox list
- Page 99 and 100:
Chapter 3 } "MSXML2.XMLHTTP.4.0", "
- Page 101 and 102:
'TEXT: ' . $errStr . chr(10) . 'LOC
- Page 103 and 104:
etrieve the parameters $num = 1; //
- Page 105 and 106:
Chapter 3 Figure 3.16: Flowchart De
- Page 107 and 108:
} Chapter 3 // only continue if xml
- Page 109 and 110:
} throw(response.length == 0 ? "Ser
- Page 111 and 112:
function process() { // ... if (req
- Page 113 and 114:
Chapter 3 Working with MySQL A back
- Page 115 and 116:
Chapter 3 Figure 3.17: Executing SQ
- Page 117 and 118:
Chapter 3 SELECT user_id, user_name
- Page 119 and 120:
3. In your foundations folder, crea
- Page 121 and 122:
Chapter 3 After these commands exec
- Page 123 and 124:
Chapter 3 • friendly.php is a PHP
- Page 125 and 126:
This example requires a JavaSc
- Page 127 and 128:
} } // try to connect to the server
- Page 129 and 130:
Chapter 3 } // create HTML-formatte
- Page 131 and 132:
Chapter 3 On the server side, all t
- Page 133 and 134:
4 AJAX Form Validation Validating i
- Page 135 and 136:
Chapter 4 Always validate user inpu
- Page 137 and 138:
Chapter 4 Figure 4.4: Successful Su
- Page 139 and 140:
Chapter 4 .left { margin-left: 150p
- Page 141 and 142:
Chapter 4 value="" />
- Page 143 and 144:
Registration Successfull! <<
- Page 145 and 146:
Chapter 4 } } { // display error me
- Page 147 and 148:
Chapter 4 require_once ('config.php
- Page 149 and 150:
Chapter 4 } { } $_POST['txtBthDay']
- Page 151 and 152:
Chapter 4 } } ?> return ($value ==
- Page 153 and 154:
Chapter 4 The field ID and value re
- Page 155 and 156:
Chapter 4 If we are dealing with cl
- Page 157 and 158:
5 AJAX Chat We are living in a worl
- Page 159 and 160:
Chapter 5 Implementing AJAX Chat We
- Page 161 and 162:
Chapter 5 // default the last id to
- Page 163 and 164:
} Chapter 5 ' DATE_FORMAT(posted_on
- Page 165 and 166:
Chapter 5 AJAX Chat Your b
- Page 167 and 168:
* function called when the Send but
- Page 169 and 170:
} } // retrieve the arrays from the
- Page 171 and 172:
Chapter 5 } } } // call server asyn
- Page 173 and 174:
Chapter 5 If you analyze the code f
- Page 175 and 176:
The business logic behind chat.php
- Page 177 and 178:
6 AJAX Suggest and Autocomplete Sug
- Page 179 and 180:
Chapter 6 The clever part of the Ja
- Page 181 and 182:
Chapter 6 6. Create another file na
- Page 183 and 184:
Chapter 6 { } a { } font-weight: bo
- Page 185 and 186:
Chapter 6 } { // try to create XMLH
- Page 187 and 188:
Chapter 6 } } } } { } displayError(
- Page 189 and 190:
Chapter 6 div += "" + "" + crtFunct
- Page 191 and 192:
} } // select the new suggestion an
- Page 193 and 194:
Chapter 6 } } else // FF if (oText.
- Page 195 and 196:
Chapter 6 Figure 6.4: PHP Documenta
- Page 197 and 198:
Chapter 6 We have talked about cach
- Page 199 and 200:
Chapter 6 visible, we need to scrol
- Page 201 and 202:
7 AJAX Real-Time Charting with SVG
- Page 203 and 204:
Chapter 7 Figure 7.1: SVG Chart The
- Page 205 and 206:
Chapter 7 Figure 7.2: SVG Charting
- Page 207 and 208:
Chapter 7 } { xmlHttp.onreadystatec
- Page 209 and 210:
} } // sets the X and Y attributes
- Page 211 and 212:
Chapter 7 } // Supported by Mozilla
- Page 213 and 214:
Chapter 7 • All HTTP requests go
- Page 215 and 216:
8 AJAX Grid Data grids have always
- Page 217 and 218:
Chapter 8 Figure 8.2: AJAX Grid in
- Page 219 and 220:
$name = $_GET['name']; // update th
- Page 221 and 222:
} Chapter 8 if (!isset($_SESSION['r
- Page 223 and 224:
Chapter 8 # editId(, true) Edit
- Page 225 and 226:
Chapter 8 } // this should work for
- Page 227 and 228:
} Chapter 8 if(editableId) editId(e
- Page 229 and 230: } color: darkblue; text-align: righ
- Page 231 and 232: Chapter 8 On the client, this data
- Page 233 and 234: Chapter 8 save() and undo() are hel
- Page 235 and 236: 9 AJAX RSS Reader In the last few y
- Page 237 and 238: Chapter 9 Figure 9.1: Managing RSS
- Page 239 and 240: header('Pragma: no-cache'); header(
- Page 241 and 242: Chapter 9 Loading feed... Abou
- Page 243 and 244: Chapter 9 } // continue if the proc
- Page 245 and 246: Chapter 9 } width: 410px; backgroun
- Page 247 and 248: And finally, we send the HTTP reque
- Page 249 and 250: 10 AJAX Drag and Drop When drag-and
- Page 251 and 252: Chapter 10 The Prototype features a
- Page 253 and 254: Chapter 10 When dropping a task on
- Page 255 and 256: Chapter 10 DROP HERE TO DELETE
- Page 257 and 258: header('Expires: Fri, 25 Dec 1980 0
- Page 259 and 260: Chapter 10 } } } else if (action ==
- Page 261 and 262: Chapter 10 11. Load http://localhos
- Page 263 and 264: details are saved using a cache sys
- Page 265 and 266: Chapter 10 Summary This is it! You'
- Page 267 and 268: A Preparing Your Working Environmen
- Page 269 and 270: Appendix A During installation you'
- Page 271 and 272: Before going through any case studi
- Page 273 and 274: Appendix A Preparing Your *nix Play
- Page 275 and 276: 8. Finally, point your web browser
- Page 277 and 278: 2. Write ajax in the Create a new d
- Page 279: Index A abort() method, XMLHttpRequ
- Page 283 and 284: PHP Parameters and Error Handling r
- Page 285 and 286: updateChart() function, realTimeCha