简体   繁体   English

如何使用ajax从数据库中获取价值以下拉列表?

[英]How to get value to dropdown from database using ajax?

I have dropdown with some optional value.if change the those value based on that will display another dropdown with value from database.I am doing this process in jsp page.First dropdown values are static(coded in jsp).but second dropdown values are come from database when changeevent of first dropdown. 我有一些可选值的下拉列表。如果更改这些值,将显示另一个带有数据库值的下拉列表。我正在jsp页面中执行此过程。第一个下拉列表值是静态的(用jsp编码),但是第二个下拉列表值是静态的来自第一个下拉菜单的changeevent时的数据库。

Here i need to implement ajax or javascript ? 在这里我需要实现ajax或javascript吗? Could you give me examples of this drop down. 您能给我举这个例子吗?

You can do it with JQuery and Ajax pretty easily. 您可以使用JQuery和Ajax轻松完成此操作。 Check out http://www.chazzuka.com/experiments/jquery-dropdown/ 查看http://www.chazzuka.com/experiments/jquery-dropdown/

for an example 举个例子

You have two drop down 你有两个下拉

<select id="first" onchange="get_result();" >
    somevale
</select>


<select name="second" >
</select>

now you need to give body to our get_result function 现在您需要将主体赋予我们的get_result函数

function get_result()
{
      var value = $("#id).val();
      JQuery.ajax("some_url",{ id : value }, function(){} )
}

This way you can do this. 这样您就可以做到这一点。 You specific check JQuery tutorial. 您具体检查一下JQuery教程。

Here i need to implement ajax or javascript ? 在这里我需要实现ajax或javascript吗?

Ajax. 阿贾克斯

Could you give me examples of this drop down. 您能给我举这个例子吗?

JQuery works fine. jQuery的工作正常。 I found DWR framework to be easier to understand for newcomers to Ajax. 我发现DWR框架对于Ajax的新手来说更容易理解。 You can look at tutorials on that here . 您可以在此处查看有关该主题的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM