jQuery的自动完成与多个来源

汤姆·S

我有一个带有单选按钮和自动完成输入字段的Web表单。基于选定的单选按钮,需要调用其他Web服务(URL)来处理用户在输入字段中输入的数据。以下代码效果很好,但是我不知道如何使其更灵活地接受不同的URL。

        $("#txtCriteria").autocomplete({
    source: function (request, response) {
        $.ajax({
            async: false,
            delay: 500,
            url: "../../CommonWebServices/wsEntity.asmx/ReportBuildings",
            data: "{ 'Name': '" + request.term + "'}",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataFilter: function (data) { return data; },
            success: function (data) {
                response($.map(data.d, function (item) {
                    return {
                        label: item.Text,
                        value: item.Value
                    }   // end of return
                })) // end of response
            }   // end of success
        });     // end of ajax
    },  // end of source
    minLength: 1,
});

这是单选按钮。因此,如果我选择“区域”,则Web服务URL将不同于“建筑物”。

                        <input id="Radio1" type="radio" value="S" name="rblRptChoice" class="label" checked="checked" />State Wide<br />
                <input id="Radio2" type="radio" value="P" name="rblRptChoice" class="label" />Prosperity Region<br />
                <input id="Radio3" type="radio" value="R" name="rblRptChoice" class="label" />Region<br />
                <input id="Radio4" type="radio" value="T" name="rblRptChoice" class="label" />Cluster<br />
                <input id="Radio5" type="radio" value="C" name="rblRptChoice" class="label" />CEPD<br />
                <input id="Radio6" type="radio" value="F" name="rblRptChoice" class="label" />Fiscal Agency<br />
                <input id="Radio7" type="radio" value="B" name="rblRptChoice" class="label" />Building<br />
                <input id="Radio8" type="radio" value="P" name="rblRptChoice" class="label" />CIP Code<br />
                <input id="Radio9" type="radio" value="Y" name="rblRptChoice" class="label" />Year<br /><br />
                <asp:Label ID="lblDetails" runat="server" Text="Enter Details"></asp:Label><br />
                <input id="txtCriteria" type="text" placeholder="Enter Criteria" style="width:250px" />

任何帮助表示赞赏。

汤姆·S

选择单选按钮时,我将路径值放在变量中,然后将URL设置为变量。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章