AJAX、PHP、XML 和级联下拉列表

发布于 2024-08-30 21:44:38 字数 403 浏览 4 评论 0 原文

您建议使用哪些 PHP 库来实现以下功能:

  • 三个依赖下拉列表
  • 三个 XML 数据源
  • 基于 AJAX

本质上,我想创建一个 XML 数据库并连接一个表单,允许用户选择三个不同的依赖参数:

  1. 用户点击地区
  2. 用户点击地区(按地区过滤)
  3. 用户点击车站(按地区过滤)

即使我想使用 PHP 和 XML,一般问题是:

  • 一个 XHTML 表单
  • 三个相关的级联下拉列表
  • 三个平面文件(无关系数据库)对于列表数据的

解决方案必须高效、简单、可靠、跨浏览器。

您会推荐哪些技术来解决该问题?

谢谢你!

What PHP libraries would you recommend to implement the following:

  • Three dependent drop-down lists
  • Three XML data sources
  • AJAX-based

Essentially, I'd like to create an XML database and wire up a form that allows the user to select three different dependent parameters:

  1. User clicks Region
  2. User clicks District (filtered by Region)
  3. User clicks Station (filtered by District)

Even though I would like to use PHP and XML, the general problem is:

  • One XHTML form
  • Three dependent, cascading drop-down lists
  • Three flat files (no relational database) for the list data

The solution must be efficient, simple, reliable, and cross-browser.

What technologies would you recommend to solve the problem?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

中二柚 2024-09-06 21:44:38

我想说的是 jQuery 和 自动完成插件

  • 制作三个传统的文本框并使用 autocomplete() 增强它们
  • ,每个文本框在用户键入时从服务器请求数据,通过 AJAX GET 请求,
  • 服务器将匹配的数据作为基于行的文本发送回,其中打开自动完成插件用于显示选项列表的
  • 连接处理程序 下拉列表的 result 事件,存储所选选项。
  • 第二个文本框需要设置第一个文本框,因此
  • 每个文本框都会从服务器请求数据,包括所有先前选择的选项,以便服务器可以找到
  • 服务器使用的正确数据DOMDocumentDOMXPath 来获取数据,自动完成插件具有内置的客户端缓存,可以减轻服务器上的负载

I'd say jQuery and the Autocomplete plugin.

  • make three conventional text boxes and enhance them with autocomplete()
  • each one requests data from the server as the user types, via AJAX GET requests
  • the server sends back the matching data as line-based text, which in turn the autocomplete plugin uses to display a list of options
  • hook up an handler for the result event of the dropdowns, storing the selected option.
  • the second textbox would require the first to be set and so on
  • each textbox requests data from the server including all previously selected options so the server can find the right data
  • the server works with DOMDocument and DOMXPath to get the data, the autocomplete plugin has built-in client side caching do ease load on the server
最美不过初阳 2024-09-06 21:44:38

Vanilla php 和一个好的 JavaScript 框架就足够了。

您需要构建一个 php 脚本来根据提供的父过滤器生成经过过滤的地区和车站列表(以 xml 或 json 形式推出数据)。 php需要解析xml数据并根据条件过滤列表(显然数据库会比手动解析xml更好地处理这个问题)

然后使用js框架在每次父列表的值发生变化时查询php文件。 js 框架不是必需的(实际上会导致一些膨胀),但是它将使开发应用程序成为一项简单的任务。

就我个人而言,我推荐 jQuery,因为它易于学习,但任何流行的 js 框架都会产生相同的结果。

Vanilla php and a good JavaScript framework is all you'd need.

You'll need to build a php script to generate filtered lists of districts and stations based on the provided parent filter (pushing out the data as either xml or json). The php will need to parse the xml data and filter the list based on criteria (obviously a db will handle this better than manually parsing xml)

Then use a js framework to query the php files every time the parent list's value changes. A js framework isn't required (and actually cause some bloat), however it'll make developing the app an easy task.

Personally I'd recommend jQuery due to the easy learning curve, but any popular js framework will yield the same result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文