2013-03-26 76 views
-2

我想自定義變量發送到喜歡的自訂的網址:5.how我可以添加此code.Plz幫助如何通過ajax將自定義變量傳遞給服務器?

  $("#e8").select2({ 
      placeholder: "Search for another Concept", 
      minimumInputLength: 1, 
      multiple: true, 

      ajax: { // instead of writing the function to execute the request we use Select2's convenient helper 
       url: "sendchat3.php", 
       dataType: 'json', 
       data: function (term, page) { 
        return { 
         q: term, // search term 
         page: page 
        }; 
       }, 
       results: function (data, page) { 
        return { results: data}; 

       } 
      } 
     }); 
+0

嗯...你*的*發送自定義的數據了。 – Quentin 2013-03-26 13:42:54

+0

我猜@barryhunter答案應該可以解決你的問題 – Joberror 2013-03-26 13:43:32

回答

1
... 
      data: function (term, page) { 
       return { 
        q: term, // search term 
        customID: 5, 
        page: page 
       }; 
      }, 
... 
+0

爲什麼OP發送params函數然後返回一個數組而不是簡單地發送一個數組?這是一個好方法嗎? – 2013-03-26 13:45:43

+0

我猜select2需要一個函數,因爲它可能需要進行多個Ajax調用,即如果用戶頁面通過數據集,所以它只是執行回調函數(這恰好是anonymys函數),以獲得'數據'數組,而不是有一個靜態數組。 – barryhunter 2013-03-26 13:49:06

+0

@barryhunter謝謝,我怎樣才能在服務器端選擇它? – 2013-03-26 13:50:49

相關問題