试译《Ajax in Action》第四部分(二)

  如果你曾经在线购买过一件新衬衣,你也许会遇到如下的麻烦。你从一个下拉列表里挑选了衬衣的尺寸,又从另一个下拉列表里选择颜色。然后你提交表单,并得到一行由大大的红色字母显示的消息:“对不起,库存缺货。”挫折感开始产生并可能持续下去,因为你必须点击回退按钮或打开一个新链接选另一种颜色。有了Ajax,我们可以消除这种挫折感。我们可以把选项列表链接在一起,当我们的用户从第一个列表利选择尺寸选项的时候,所有对那种衬衣有效的颜色能直接从数据库里被填充到第二个列表里,并且不需要用户刷新整个页面。人们曾通过硬编码的JavaScript数组或服务器端回发的方法把两个或更多的选项列表绑在一起以实现这种功能,但是,现在使用Ajax是更好的途径。

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ If you have ever shopped for a new shirt online, you may have run into the following problem. You pick the shirt size from one drop-down list, and from the next drop-down list you select the color. You then submit the form and get the message in giant red letters: “Sorry, that item is not in stock.” Frustration sets in as you have to hit the back button or click a link to select a new color.  With Ajax we can eliminate that frustration. We can link the selection lists together, and when our user selects the size option from the first list, all of the available colors for that shirt can be populated to the second list directly from the database—without the user having to refresh the whole page. People have been linking two or more selection lists together to perform this action with either hard-coded JavaScript arrays or server-side postbacks, but now with Ajax we have a better way.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值