简体   繁体   English

定制的动态Web表单

[英]customized dynamic web forms

I have a web form that has 2 drop down menus, when the first drop down menu chooses something, I want the next drop down menu to populate according to the selection on the first drop down menu without the page reloading. 我有一个具有2个下拉菜单的Web表单,当第一个下拉菜单选择某些内容时,我希望根据第一个下拉菜单上的选择填充下一个下拉菜单,而无需重新加载页面。 Would I use ajax for this? 我会为此使用ajax吗? What is the best way to accomplish this? 做到这一点的最佳方法是什么? Anyone have any good tutorials for this? 有人对此有任何好的教程吗?

Of course you should use ajax. 当然,您应该使用ajax。
JQuery provides you with this functionality. JQuery为您提供此功能。

Create a webservice and add to it a method that returns a list of a certain object. 创建一个Web服务,并向其添加一个返回特定对象列表的方法。
in your javascript file, on the selectedindexchange of the first drop down list write the below 在您的javascript文件中,在第一个下拉列表的selectedindexchange上,输入以下内容

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    url: WebServiceUrl/methodname,
    data: "{id: '" + id + "'}",
    success: LoadDataSuccedded,
    error: LoadDataFailure
});

function LoadDataSuccedded(result, e)
{
    var data = result.d;
    //fill the second drop down list
}

function LoadDataFailure(result, e)
{

}

check this link for more clarification http://api.jquery.com/jQuery.ajax/ 检查此链接以获取更多说明http://api.jquery.com/jQuery.ajax/

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

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