问题描述
$(document).ready(function () {
$('[id$=tagsinput]').tagsinput({
itemValue: 'value',
itemText: 'text',
typeahead: {
source: function (query) {
var str;
$.ajax({
type: "POST",
url: "CityNamesData.asmx/GetCities",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
str = data.d;
}
});
var str1 = $.getJSON(str);
return str1;
//var str = $.getJSON('assets/cities.json'); //This line is working fine if we want to retrieve data from json file.
}
}
});
//Below code shows tags into the asp.net textbox control
$('[id$=tagsinput]').tagsinput('add', { "value": 1, "text": "Amsterdam" });
$('[id$=tagsinput]').tagsinput('add', { "value": 4, "text": "Washington" });
$('[id$=tagsinput]').tagsinput('add', { "value": 7, "text": "Sydney" });
$('[id$=tagsinput]').tagsinput('add', { "value": 10, "text": "Beijing" });
$('[id$=tagsinput]').tagsinput('add', { "value": 13, "text": "Cairo" });
})
我正在尝试将来自web方法的数据保存到str1中,如下所示
var str1 = $ .getJSON( str);
返回str1;
str1以先前在str中保存的格式保存数据。
但是当我有试图返回str1,它没有向文本框显示建议。
str和str1将json数据存储到相同的格式。但它只显示我返回str时的建议。
任何人都可以告诉我如何返回来自WebMethod的数据,以便在文本框中显示建议。
我不知道str1有什么问题。
I am trying to save data coming from web method into str1 as follows
var str1 = $.getJSON(str);
return str1;
str1 saves data in the same format as it was previously saved in str.
But still when I have tried to return str1, its not showing suggestions into the textbox.
str and str1 are storing json data into the same format.But it is only showing suggestions when I am returning str.
Can anyone please tell me how to return this data coming from WebMethod so that it would show suggestions in textbox.
I dont know whats wrong with str1.
推荐答案
这篇关于如何将Web方法添加为Bootstrap Taginput的源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!