Javascript jquery ajax调用未在引导打印头中触发

Javascript jquery ajax调用未在引导打印头中触发,javascript,jquery,ajax,bootstrap-typeahead,Javascript,Jquery,Ajax,Bootstrap Typeahead,我试着用Ajax做一个推特引导打印头,但什么也没发生。没有错误,没有输出 这是我的jquery ajax代码 function CallData() { $('input.typeahead.local.remote').typeahead({ source: function (typeahead,query) { $.ajax({ type: "GET", url: "h

我试着用Ajax做一个推特引导打印头,但什么也没发生。没有错误,没有输出 这是我的jquery ajax代码

    function CallData() {

    $('input.typeahead.local.remote').typeahead({
        source: function (typeahead,query) {
            $.ajax({
                type: "GET",
                url: "http://cs-api-sandbox.herokuapp.com/v1/challenges/search?keyword=r&callback=my_callback",
                jsonpCallback: "my_callback",
                dataType: "jsonp",
                error: function (xhr, errorType, exception) {
                    var errorMessage = exception || xhr.statusText;
                    alert("Excep:: " + exception + "Status:: " + xhr.statusText);
                }
            });
        }
    });

}

function my_callback(data) {
    alert('hi');
}
这是我的html代码

<input type="text" id="txt" runat="server" class="span4 typeahead local remote" placeholder="Search..." />


我在每次按键时都调用ajax函数
CallData()
,但什么都没有发生

您需要将ajax请求的结果传递给source的第二个参数(这是一个用于填充前面类型的回调)。一个人为的例子:

$('#mytypeahead').typeahead({
    source: function(query, process){
        $.ajax({
            url: '/some/url?query='+query,
            success: function(response){
                process(response);
            }
        });
    }
});

尝试将
async:false
添加到$.ajax中-因为javascript的机制是不同步的。
希望获得此帮助

是否触发了任何
alert()
调用?不,不会触发