2013-07-15 22 views
0

使用Select2非常困難,但該組件非常值得學習曲線。在Select2處理程序中看不到服務器結果

這裏是我的組件:

$('#e1').select2({ 
       placeholder: "Select participants", 
       minimumInputLength: 1, 
       allowClear:true, 
       multiple: true, 
       ajax: { 
        url: "/transporter/app/search", 
        dataType: 'jsonp', 
        data: function (term, page) { 
         return { 
          query:term + '*', 
          searchFor:'users', 
          sortBy:'relevance', 
          format:'json', 
          page_limit:10 
         }; 
        }, 
        results: function (data, page) { 
         alert(data) 
         // return { results: data.response.userList.user }; 
        } 
       }, 
       formatResult: formatContacts, 
       formatSelection: formatContactsSelection, 
       escapeMarkup: function(m) { return m; } 
      }); 

      function formatContacts(item) { 
       alert("GO") 
       return item.displayName; 
      }; 

      function formatContactsSelection(item) { 
       alert("HERE") 
       return item.loginName; 
      }; 

問題是,在Chrome網絡調試我看到返回有效的JSON,但結果處理程序不扔警報(數據)。爲什麼會這樣?

回答

0

罪魁禍首:數據類型: 'JSONP'

這顯然與格式干擾: 'JSON'。

我拿出來了。

相關問題