ColdFusion的填充表单与下拉选择用ajax [英] Coldfusion Populate form with dropdown selection using ajax

查看:207
本文介绍了ColdFusion的填充表单与下拉选择用ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个使用ColdFusion的一个项目,它有一个下拉的表单。

So I have a project that's using ColdFusion and it has a form with a dropdown.

See example: http://jsfiddle.net/mwoods98/KXmNK/

我需要一次下拉列表中选择要发生,是一个Ajax调用来调用一个ColdFusion CFC,返回的信息填写表格是这样的下拉列表下。

What I need to happen once the dropdown is selected, is for an ajax call to call a ColdFusion cfc that returns information to fill in the form that's under the dropdown.

使用小提琴上面作为一个例子,如果用户选择2,那么,名称字段将具有鲍勃,202假街和111-555-1234。如果他们选择了3,他们将得到什么东西从CFC(数据库)返回。

Using the fiddle above as an example, if the user selected "2" then the name field would have Bob, 202 Fake Street and 111-555-1234. If they selected "3" they would get whatever else is returned from the CFC (database).

在CFC只会有一个方法调用,将基于抢关通过下拉提交的数量值的信息。

The CFC would just have a method call that would grab information based off of the value of the number submitted via the dropdown.

任何帮助将是AP preciated。

Any help would be appreciated.

感谢

推荐答案

如果你正在使用jQuery,您可以使用内置的jQuery的AJAX功能,调用到CFC并返回结果并填充字段。顺便说一句,如果你想要做的这个领域将ID将是非常有益的。

If you are using jQuery you can use the ajax function built into jquery to call to the CFC and return the result and populate the fields. BTW if you want to do this putting IDs on the fields will be VERY helpful.

$.ajax({
    type: 'get',
    url: 'pathToMy.cfc',
    data: {method:'getNameAddressAndNumberFromID'
        , myID : valueOfItemSelectedInDropDown
        },
    dataType: 'json',
    async: false,
    success: function(result){
         $('#myNameInput').val(result.NAME);
         $('#myNameInput').val(result.ADDRESS);
         $('#myNameInput').val(result.NUMBER);
        }
    }); 

假设你有一个名为pathToMy.cfc'与'getNameAddressAndNumberFromID的方法CFC和你有类似名称的输入ID:

Assume you have a CFC named 'pathToMy.cfc' with a method of 'getNameAddressAndNumberFromID' and you have an ID on the inputs like Name:

<input name="name" id="myNameInput" type="Text">

的方法的结果可以从查询返回的名称,地址和电话号码。回到这个信息作为JSON将是非常有益的。

the result of the method could return the name, address and number from a query. Returning this info as JSON will be really helpful.

这应该让你在正确的轨道,祝你好运。

This should get you on the right track, good luck.

这篇关于ColdFusion的填充表单与下拉选择用ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆