English 中文(简体)
AJAX, PHP, XML, and cascading drop-down lists
原标题:

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!

最佳回答

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
问题回答

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.





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签