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

查看:25
本文介绍了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",那么名称字段将包含 Bob、202 Fake Street 和 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.

任何帮助将不胜感激.

谢谢

推荐答案

如果您使用的是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"的 CFC,其方法为getNameAddressAndNumberFromID",并且您在输入上有一个 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天全站免登陆