【发布时间】:2014-12-14 07:13:47
【问题描述】:
我一直在尝试 tokeninput 。它就像一个魅力。但最近我偶然发现了一个要求,即在同一个输入栏上进行两次 ajax 调用。
场景:我的输入栏
<input id="autocompleteMe" >
我通过以下方式初始化tokeninput 插件:
$("#autocompleteMe").tokeninput(
"mysite/LookUp.php?callFrom=FromFile",
{
theme : "facebook",
propertyToSearch : "myProp"
}
);
这可以正常工作并获得结果并用结果填充我的下拉列表。
要求: 此结果来自我的 Server 上的文件。如果找到/未找到结果(在这两种情况下),我还需要在我的数据库中查找相同的输入,并提供建议。由于数据库可能已经更新。
即在用户输入时,应该触发两个 ajax 调用,它们是:
- 从文件中获取结果(我想尽快绑定 结果返回)
- 也从数据库中获取结果(这可能需要 时间 。并将在下拉列表中添加 检索)。
我的想法:
$("#autocompleteMe").tokeninput(
"mysite/LookUp.php?callFrom=FromFile",
{
theme : "facebook",
propertyToSearch : "myProp",
onResult : function(result){
// bind the returned results here to the dropdown . Since they are from the file
// but how ?
$.getJSON("mysite/LookUp.php",{callFrom : "DBCall"},function(DBResponse){
// append the results to the dropdown .
// also this will a async call . i will have attach the callback . I have no idea how to
});
}
}
);
为这么愚蠢的问题道歉。但我一直在努力解决这个问题。 任何帮助都是有义务的。
感谢和问候!
【问题讨论】:
-
这只是异步调用的问题还是别的什么?
标签: javascript jquery ajax jquery-tokeninput