Section 6.3. The problem with Boards R Us


6.3. The problem with Boards 'R' Us

The Boards 'R' Us report still uses an asynchronous request to talk to the server, and since you solved their caching problems, the report works for everyone in the company (including Katie's man running Windows).

But the server needs to send back three sales numbers now: the total number of boards sold, as well as the number of boots and bindings sold.

 This is the same request as in the version of the report that only dealt with snowboards. Request Updated Sales Totals PHP script In  this new version, the server has to send back three numbers: the sales totals for boards, boots, and bindings. PHP script How  can Katie's PHP script send back three different numbers at the same time? 

Great! Someone finally wants me to say more, and I don't know how. I HATE being a server!

Dr. Zigmund: Progress, my dear friend! Now people vant to hear you.

Server: But how can I say three things at one time? This is my only chance... and I'm going to blow it.

Dr. Zigmund: I don't zink you have been using my pre-zcription, have you?

Server: I could just string the three sales totals together, and a space between them... no, that's a pretty crummy idea...

Dr. Zigmund: Have you con-zidered zee XML?

Server: Maybe comma-separated values? Those are big in spreadsheets... but no, the commas could get mistaken as part of the total itself...

Dr. Zigmund: Now I wonder who is not listening to whom... young man, I'm trying to tell you...

Server: If I just had a way to send data in a format that I know the Boards report would be able to understand... I know Katie hates anything that might break in a few months, or isn't standardized..

Dr. Zigmund: Zees is hopeless. Zere is no cure for zee clueless zerver, it zeems.

OK, look... I'm loving this cute little story, but I've got it, OK? The stupid server needs to use XML, right? That's the answer to the Boards problem?

But do you understand why?

XML can definitely help Katie out with her online report. So far, you've used plain text to send responses back to the web browser... but that's just because you've only had to return a single piece of data, like an address, or the number of minutes until a pizza will show up.

When you need to get more than just a single piece of information from the server, though, things get a little trickier. You've seen that using proprietary data formats just isn't the answer:

 1710;315;85 Here are some examples of the server sending back data using a "made up" data format. 1710,315,85 There are three numbers in this response, but both the server and the browser have to know what the semicolon means... ...and in this case, it's unclear what purpose the comma serves. Does it separate different numbers? Is this all one number? 1710|315|85 Boy, better hope nobody ever changes the order of these sales totals... that would be bad, bad, bad! Even worse: what happens if the order of the data returned changes? Everything breaks! 




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net