为了设置两个相关的下拉列表,我使用了jQuery.ajax,但我遇到了一些麻烦,并且我认为我在$.ajax上设置的控制器操作的url是不可访问的。
这是我的控制器动作代码:
public function fillIncidentsAction()
{
$request = $this->getRequest();
if ($request->isPost())
{
$code_categ = (int) $request->getPost('code_categ',0);
$data = new JsonModel(array(
'success' => true,
'results' => $this->getTableInstance('TypeIncidentTable')
->getListTypeIncident($code_categ),
));
return $data;
}
}这是我的js函数的主要部分。
$('#'+source).change(function() {
if($('#'+source).val() != '')
{
$.ajax({
type: 'POST',
async: false,
url: url,
cache: true,
dataType: 'json',
data: { code_categ: $('#'+source).val() },
success: function(data){
alert(data.success);//<------ i added this to test if this function is executed or not
if(data.success)
{
$('#'+target).prop('disabled', true);
if(data.results != ""){
var options = new Array();
$.each(data.results, function(key, value){
options[((key) ? key : 0)] = '<option value="' + key + '">' + value + '</option>';
});
$("#"+target).html(options.join(''));
$('#'+target).prop('disabled', false);;
}
}
},
});我不知道我哪里错了。有什么建议吗?感谢您的帮助!
对不起,我的url是这样设置的:
<script type="text/javascript">
$(document).ready(function() {
var url = "<?php echo $var =$this->url('gims/default', array('controller' => 'evenement', 'action' => 'fill_incidents')); ?>";
// initialize the js function
dependentDropDown('firstList','secondList',url);
});
</script>希望这能给你更多的细节。
发布于 2013-08-14 21:47:16
问题出在我的moodule.config.php上,我还没有启用Json策略。
'view_manager' => array(
//...
'strategies' => array(
'ViewJsonStrategy',
),
),https://stackoverflow.com/questions/18229057
复制相似问题