Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
$(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" });
         })

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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900