duancaiyi7567 2015-11-07 16:34
浏览 23

Javascript自动完成 - 不填充

I am experiencing some challenges getting my autocomplete box to populate.

I am sending multiple parameters to the source. My current attempt ...

 $("#questionBox").autocomplete({
    source: function(request, response) {
        $.ajax({
            url: "csvAPI.php",
            dataType: "json",
            data: {
                term: request.term,
                discipline: $("#disciplineNameSelect option:selected").text(), 
                questionType: $("#questionTypeSelect option:selected").text(),
                surveyTitle: $("#surveyTitleSelect option:selected").text()
            },
            success: function(data) {
                response(data);
            }
        });
    },

You can see the source url does work with the parameters sent ...

http://tinyurl.com/ptl7e9g

Any suggestions on how to get this to work? I have tried many different variations. I can get it to work when I define the source choices manually. But I need it to be dynamic with 4 parameters sent.

Thanks!

  • 写回答

1条回答 默认 最新

  • doulu2011 2015-11-07 17:20
    关注

    Thank you for the suggestion to the other answer. I was able to get it to work! Mapping the label and value worked. This is important for anyone trying to get jquery autocomplete to work. If your source data is very plain and it does not include label and value you need to map it in the javascript. This now works ...

    $('#questionBox').autocomplete({
        source: function (request, response) {
            var qbString = "csvAPI.php?term=" + request.term + "&call=questionBoxAutoComplete" + "&discipline=" + $("#disciplineNameSelect option:selected").text() + "&questionType=" + $("#questionTypeSelect option:selected").text() + "&surveyTitle=" + $("#surveyTitleSelect option:selected").text();
            $.getJSON(qbString, function (data) {
                response($.map(data, function (value, key) {
                    return {
                        label: value,
                        value: key
                    };
                }));
            });
        },
        minLength: 2,
        delay: 100
    });
    

    And this is my dynamic source data essentially ...

     {"0":"What is your revenue breakdown?","3":"What is your net operating income?","4":"What is your revenue renewal rate?","5":"What is your fee per hour?"}
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度