本文介绍了服务器端数据可在客户端使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做的是根据页面上的其他下拉列表更改下拉列表的选择。我所做的就是将所有可能性都写在隐藏的文本框中。可以,但是在有很多选择的情况下,页面速度很慢。
What I want to do is make a dropdownlist choices change depending on other dropdownlists on the page. What I did is write all the possibilities in hidden textboxes. This works, but when there are a lot of choices, the page is slow.
有没有更好的方法?
谢谢您的时间
推荐答案
做到这一点的最佳方法是使用AJAX。总之,您将需要:
The best way to do this is with AJAX. In summary you will need to:
- 编写服务器端脚本(可能是ashx),该脚本返回相关结果以供依赖于某些对象的下拉列表使用变量
- 使用JavaScript(或类似jQuery的库)对ashx页面进行AJAX调用。此调用将需要通过POST或GET将定义变量传递给服务器。
- 将此AJAX调用附加到选择框的change事件,以便在更改它们时其他框可以更新
- 完成AJAX调用后,您将需要一个JavaScript函数来对返回的数据进行排序。此数据可以是添加到页面的简单HTML,也可以是需要格式化的更复杂的JSON对象。这是你的选择。但是这种格式和响应需要用JavaScript编写。
- write a server side script (ashx probably) that returns the relevant results for a drop down dependent on some variable
- use JavaScript (or a library like jQuery) to do the AJAX call to the ashx page. This call will need to pass the defining variable to the server via POST or GET.
- attach this AJAX call to the change event of the select boxes so that when they are changed the other ones can be updated
- when the AJAX call is completed you will need a JavaScript function that sorts out the returned data. This data could be simple HTML that is added to the page or a more complex JSON object that needs to be formatted. The choice is yours. But this formatting and response needs to be written in JavaScript.
这篇关于服务器端数据可在客户端使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!