本文介绍了返回预先引导的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im尝试在执行ajax请求后返回bootstrap typeahead的结果,但是它不起作用,但是当我不发起ajax请求时它确实起作用.

im trying to return results for the bootstrap typeahead after doing an ajax request, but its not working however it does work when i don't initiate the ajax request.

这不起作用:

$(".typeahead").typeahead({
  source: function(query, process) {
    return $.ajax({
      url: "/typeahead",
      type: "GET",
      data: "action=" + query,
      success: function(result) {
        return result;  // this returns an array checked with console
      }
    });
  }
});

在没有ajax的情况下有效:

with no ajax it works:

  $(".typeahead").typeahead({
      source: function(query, process) {
          return ["option1", "option2", "option3"]
      }
    });

推荐答案

您应该返回process(result)而不是仅仅返回结果.

You should return process(result) instead of just returning the result.

$(".typeahead").typeahead({
  source: function(query, process) {
    return $.ajax({
      url: "/typeahead",
      type: "GET",
      data: "action=" + query,
      success: function(result) {
        return process(result);  // this returns an array checked with console
      }
    });
  }
});

这篇关于返回预先引导的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:44