2016-07-25 3 views
0

У меня есть следующие JavaScript, чтобы заполнить выпадающий список с помощью ВЫБ.2 https://select2.github.io/Получение Выбор2 для обновления данных с помощью Ajax на раскрывающемся меню

Он отлично работает, и заполнит список на первой загрузке страницы. С этого момента он не обновляет список, даже когда данные добавляются, потому что он вызывает только вызов AJAX. Даже если я перезагружаю страницу, раскрывающийся список не обновляется, и вызов AJAX не запускается (если я не закрываю и не открываю браузер, тогда выполняется вызов AJAX)

Есть ли способ совершить вызов ajax каждый время вскрытия открывается. Я попробовал вариант .on ("select2-open"), но мне не повезло.

Извините, JavaScript не то, о чем я много знаю.

$("#Location").select2({ 
      placeholder: "Select a known location", // Placeholder text 
      allowClear: true, //Allows deselection of chosen address 
      ajax: { 
       url: '/AlertInterface/NewAlertLocations', // Where we want the ajax to call 
       dataType: 'json', // The datatype we are expecting to be returned 
       type: "GET", //Just a get method 
       //Data: allows us to pass a parameter to the controller 
       data: function (query) { 
        console.log(query) 
        return { search: query.term } 
       }, 
       //processes the results from the JSON method and gives us the select list 
       processResults: function (data) { 
        console.log(data) 
        return { 
         results: JSON.parse(data) 
        }; 
       } 
      } 
     }); 

EDIT:

Я пытаюсь использовать

$("#Location").on("select2:open", function() { $("#Location").select2(); }) 

, но это не помогло. :-(

ответ

0

У вас есть синтаксические ошибки в коде Пожалуйста, проверьте код, приведенный ниже,

$("#Location").select2({ 
      placeholder: "Select a known location", // Placeholder text 
      allowClear: true, //Allows deselection of chosen address 
      ajax: { 
       url: '/AlertInterface/NewAlertLocations', // Where we want the ajax to call 
       dataType: 'json', // The datatype we are expecting to be returned 
       type: "GET", //Just a get method 
       //Data: allows us to pass a parameter to the controller 
       data: function (query) { 
        console.log(query) 
        return { search: query.term } 
       }, 
       //processes the results from the JSON method and gives us the select list 
       processResults: function (data) { 
        console.log(data) 
        return { 
         results: JSON.parse(data) 
        }; 
       } 
      } 
    }); 
+0

О господи я скопировал немного на много забыть дополнительные}).!. – cramar

+0

Сделайте свой сайт в прямом эфире, если да, укажите ссылку :) –

 Смежные вопросы

  • Нет связанных вопросов^_^