2014-02-28 14 views
0

我有一個選擇2使用Ajax插件:http://ivaynberg.github.io/select2/我如何在Cakephp中接收這個ajax參數?

$("#UserCliente").select2({ 
placeholder: "Select a State", 
minimumInputLength: 3, 
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper 
url: "../clients/listaclients/", 
dataType: 'json', 
data: function (term) { 
    return { 
     select: term, // search term 
    }; 
}, 
results: function (data) { // parse the results into the format expected by Select2. 
    // since we are using custom formatting functions we do not need to alter remote JSON data 
    return {results: data}; 
} 
} 
}); 

發送阿賈克斯PARAM:

enter image description here

我需要得到select值(屁股)。我試圖沒有成功:

$this->request['select'] 

我怎樣才能得到這個值?

+0

請注意,當您期望JSON作爲返回內容時,URL應爲'/ clients/listaclients.json'。參見[ajax-and-cakephp](http://www.dereuromark.de/2014/01/09/ajax-and-cakephp/)。另外:你應該總是提到你正在使用的確切cakephp版本。 – mark

回答

1

蛋糕的方法:$this->request->query['select']

編輯:蛋糕2.4及以上的辦法>$this->request->query('select')

本地PHP:$_GET['select']

可能是一個好主意,以獲得DebugKit插件。幫助你看到各種東西,包括請求值,並讓你知道如何訪問它們。

+0

這個作品!謝謝!! +1用於調試套件 –

+2

對於Cake2.4及以上版本,您還可以使用包裝器方法'$ this-> request-> query('select')'。 – mark