I am implementing a function populatig a select box using data from another select box.
我正在使用另一个选择框中的数据实现一个选择框的功能。
//views/users/ajax.ctp
$.ajax({
url: url,
type: "GET",
dataType: "html",
data:"arr=" + result,
success: function(data){
document.getElementById(child).innerHTML = data;
}
});
As you can see from the code above the data passed by the call should be accessible in the getSectors() function under the data
variable:
从上面的代码中可以看出,调用传递的数据应该可以在data变量下的getSectors()函数中访问:
//controllers/users_controller.php
function getSectors() {
$this->set('data', $this->data);
$this->render('/users/ajax_data');
}
In the corresponding view I try to see the content of the data passed:
在相应的视图中,我尝试查看传递的数据内容:
//views/users/ajax_data.ctp
<?php var_dump($data); ?>
The $data is null.
$ data为null。
Debugging that in Firebug shows that the call is invoked properly (status 200 ok
) and that the XMLHttpRequest contains parameters and values.
在Firebug中进行调试显示调用正确调用(状态200 ok)并且XMLHttpRequest包含参数和值。
Do you have any suggestions what could be possibly wrong?
你有什么可能错的建议吗?
1 个解决方案
#1
0
In order for Cake to populate the $this->data
variable, the data being send needs to follow the format data[Model][field]
, or at least be part of the data[..]
array. If it's plainly named arr
, Cake won't put it in the $this->data
variable.
为了使Cake填充$ this-> data变量,发送的数据需要遵循格式数据[Model] [field],或者至少是data [..]数组的一部分。如果它明确地命名为arr,那么Cake不会将它放在$ this-> data变量中。
#1
0
In order for Cake to populate the $this->data
variable, the data being send needs to follow the format data[Model][field]
, or at least be part of the data[..]
array. If it's plainly named arr
, Cake won't put it in the $this->data
variable.
为了使Cake填充$ this-> data变量,发送的数据需要遵循格式数据[Model] [field],或者至少是data [..]数组的一部分。如果它明确地命名为arr,那么Cake不会将它放在$ this-> data变量中。