AJAX In Action [1]
node 49
■ Creating a DOM node 50 ■ Adding styles to your
document 51 ■ A shortcut: Using the innerHTML property 53
2.5
Loading data asynchronously using
XML technologies 53
IFrames 54
■ XmlDocument and XMLHttpRequest objects 56
Sending a request to the server 58 ■ Using callback functions to
monitor the request 61 ■ The full lifecycle 62
2.6
What sets Ajax apart 65
2.7
Summary 67
2.8
Resources 68
3 Introducing order to Ajax 69
3.1
Order out of chaos 71
Patterns: Creating a common vocabulary 71
Refactoring and Ajax 72 ■ Keeping a sense of proportion 73
Refactoring in action 73
3.2
Some small refactoring case studies 77
Cross-browser inconsistencies: Façade and Adapter patterns 77
Managing event handlers: Observer pattern 80
Reusing user action handlers: Command pattern 83
Keeping only one reference to a resource: Singleton pattern 87
3.3
Model-View-Controller 91
3.4
Web server MVC 93
The Ajax web server tier without patterns 93 ■ Refactoring the
domain model 96 ■ Separating content from presentation 100
Licensed to jonathan zheng CONTENTS xi 3.5 Third-party libraries and frameworks 103 Cross-browser libraries 104 ■ Widgets and widget suites 108 Application frameworks 111 3.6 Summary 114 3.7 Resources 115 PART 2 CORE TECHNIQUES............................................ 117 4 The page as an application 119 4.1 A different kind of MVC 120 Repeating the pattern at different scales 120 Applying MVC in the browser 122 4.2 The View in an Ajax application 124 Keeping the logic out of the View 124 Keeping the View out of the logic 130 4.3 The Controller in an Ajax application 134 Classic JavaScript event handlers 134 The W3C event model 137 Implementing a flexible event model in JavaScript 138 4.4 Models in an Ajax application 143 Using JavaScript to model the business domain 144 Interacting with the server 145 4.5 Generating the View from the Model 147 Reflecting on a JavaScript object 147 ■ Dealing with arrays and objects 151 ■ Adding a Controller 154 4.6 Summary 157 4.7 Resources 158 5 The role of the server 159 5.1 Working with the server side 160 5.2 Coding the server side 161 Popular implementation languages 161 N-tier architectures 162 Maintaining client-side and server-side domain models 163 Licensed to jonathan zheng xii CONTENTS 5.3 The big picture: common server-side designs 164 Naive web server coding without a framework 164 Working with Model2 workflow frameworks 166 Working with component-based frameworks 167 Working with service-oriented architectures 170 5.4 The details: exchanging data 174 Client-only interactions 175 Introducing the planet browser example 175 Thinking like a web page: content-centric interactions 178 Thinking like a plug-in: script-centric interactions 182 Thinking like an application: data-centric interactions 188 5.5 Writing to the server 193 Using HTML forms 193 ■ Using the XMLHttpRequest object 195 ■ Managing user updates effectively 197 5.6 Summary 206 5.7 Resources 207 PART 3 PROFESSIONAL AJAX .......................................... 209 6 The user experience 211 6.1 Getting it right: building a quality application 212 Responsiveness 213 ■ Robustness 213 ■ Consistency 214 Simplicity 215 ■ Making it work 215 6.2 Keeping the user informed 216 Handling responses to our own requests 216 Handling updates from other users 218 6.3 Designing a notification system for Ajax 222 Modeling notifications 223 Defining user interface requirements 225 6.4 Implementing a notification framework 226 Rendering status bar icons 226 ■ Rendering detailed notifications 229 ■ Putting the pieces together 230 6.5 Using the framework with network requests 237 6.6 Indicating freshness of data 241 Defining a simple highlighting style 241 Highlighting with the Scriptaculous Effects library 243 Licensed to jonathan zheng CONTENTS xiii 6.7 Summary 244 6.8 Resources 245