首页 > 解决方案 > Ajax 动态选择框 cakephp 不起作用

问题描述

我收到此错误:

在此服务器上找不到请求的地址“/panel/admin/services/add_service”

当我提交表单并且我在选择框的控制台中获得正确的值时。

jQuery代码

$('.edit_sub_service_data2').css('display','none');
$('#service_provider_id').change(function(){ 

   var cat_val=$(this).val();
    var hiturl= "<?php echo $this->webroot.'admin/test/get_provider?cat_id='; ?>"+cat_val;
    jQuery.ajax({
            url:hiturl,    // Send the data with your url.
            type: "GET",
            data:  {'cat_val': cat_val}, 
            dataType: "json",   
            success: function(data){ 
              $('#service_service_data_id').html("");
              $('#service_service_data_id').html(data[0]);
              }               
        });

  });

PHP代码

    foreach ($category_data as $key => $value){
    $combo[] ="<option value='".$key."'>".$value."</option>";    
    }
    echo json_encode(array($combo));
    exit();

表格提交代码

  <?php echo $this->Form->input('service_data',array('class'=>'form-control','type'=>'select','id'=>'service_service_data_id')); ?>

此代码显示动态数据,但是当我提交表单时,我的表单没有提交,只是因为 CakePhp 中的这个下拉菜单

标签: jqueryajaxcakephp

解决方案


推荐阅读