dongying9756 2012-12-12 17:31
浏览 34

使用数据库中的数据进行Ajax实时搜索

I've seen some (well-explained) examples where the available results of a live search are found in an xml file. But only a few (badly-explained) ones where the results come from a database. I'm interested in the second case.

One solution could be to prefetch the database data and put them in an xml object and the rest could work the same way. And this is something I can easily implement.

What I'm looking for is for another way, where the user types a letter (e.g. 'c') and the suggestions are generated on the spot (e.g. 'carrot', 'cabbage', 'celery', 'citrus'). Would this be achieved with a call to the database like

"SELECT name FROM vegetables WHERE name LIKE c%"?

And what if the user then presses another letter? (e.g. 'ca', so the recommended results should be 'carrot', 'cabbage'). Every key pressed should initiate a new SELECT? For some reason it doesn't sound like a good solution.

Is there a way to achieve this second method?

  • 写回答

1条回答 默认 最新

  • douyingtai6662 2013-10-21 11:27
    关注

    You can achieve this by sending ajax requests on every key up function in jquery. In response send back the results in json format so as to display them in a unordered list below the text field. On clicking of the li of this fill the textbox with the value in the text field.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?