动态依赖选择框使用Ajax jQuery cakephp

时间:2014-04-04 21:12:29

标签: php jquery ajax cakephp

您好我正在尝试在cakephp中选择动态并且我正在使用postgres y有此错误

GET http://localhost:8080/img/ajax-loader_mini.gif 404 (Not Found) jquery-1.3.2.min.js:12
(anonymous function) jquery-1.3.2.min.js:12
o.extend.each jquery-1.3.2.min.js:12
o.extend.clean jquery-1.3.2.min.js:12
o.fn.o.domManip jquery-1.3.2.min.js:12
o.fn.o.append jquery-1.3.2.min.js:12
o.fn.o.html jquery-1.3.2.min.js:12
$.ajax.beforeSend add:61
o.extend.ajax jquery-1.3.2.min.js:19
(anonymous function) add:57
o.event.handle jquery-1.3.2.min.js:19
(anonymous function) jquery-1.3.2.min.js:19
GET http://localhost:8080/soyasubrubros/getByRubro/1 404 (Not Found) jquery-1.3.2.min.js:19
o.extend.ajax jquery-1.3.2.min.js:19
(anonymous function) add:57
o.event.handle jquery-1.3.2.min.js:19
(anonymous function)

在我的添加中我有一些jquery我想要发送他的控制器并从那里发送子类别列表mi添加我有它。  add.ctp

  **<div class="soya form">
     <h3>Empresas Registradas para Adquisición de Grano</h3>
    <?php echo $this->Form->create('SoyaClienteDerivado');?>
    <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
        <fieldset>
            <?php 

            echo $this->Form->input('soya_rubro_id', array( 
                 'options' => $rubros,
                 'id' => 'PostRubroId',
                 'empty' => '--Porfavor selecione--','label' => 'Seleccione rubro' ));

            echo $this->Form->input('soya_subrubro_id', array( 
                 'id' => 'PostSubrubroId',
                 'empty' => '--Porfavor selecione--','label' => 'Seleccione subrubro' ));
            echo $this->Form->submit('Agregar Cliente', array('class' => 'form-submit',  'title' => 'Presione aqui para agregar datos')); 
    ?>
    <script>
    $("document").ready(
    function() {
        $('#PostRubroId').bind('click', function()
        {
            $.ajax({
                   type: "GET",
                   url: "/soyasubrubros/getByRubro/"+$(this).val(),
                   beforeSend: function() {
                         $('#PostSubrubroId').html('<div class="rating-flash" id="cargando_div">Cargando  <img src="/img/ajax-loader_mini.gif"></div>');
                         },
                   success: function(msg){
                       $('#PostSubrubroId').html(msg);
                   }
                 });
        });
    }
    );
    </script>

    </fieldset>
    <?php echo $this->Form->end(); ?>

    </div>**

这是类别列表的生成器

class SoyasubrubrosController extends AppController {
    public $components = array('Session','RequestHandler');
    public function getByRubro($id = null) {
        $this->layout = 'ajax';
        $this->loadModel('SoyaSubrubro');
        $subcategorias = $this->SoyaSubrubro->find('list',array('conditions' => array('SoyaSubrubro.soya_rubro_id' => $id), 'fields' => 'subrubro'));
        $this->set('listado_subcategorias',$subcategorias);
    }
}

这里是我想要生成列表的地方

    class SoyaclientederivadosController extends AppController {

        public $components = array('Session','RequestHandler');
        public $uses = array('SoyaClienteDerivado','SoyaRubro','SoyaSubrubro');  

        public function add()
        {
                $this->loadModel('SoyaClienteDerivado');
                $this->loadModel('SoyaAsociaciones');
                $this->loadModel('Ciudad');
            $this->set('asociaciones', $this->SoyaAsociaciones->find('list', array('fields'=>array('id','nombre'))));
            $this->set('rubros', $this->SoyaRubro->find('list', array('fields'=>array('id','rubro'))));

            $this->set('ciudades', $this->Ciudad->find('list', array('fields'=>array('id','nom_ciudad'))));


            if ($this->request->is('post')) {
                $this->SoyaClienteDerivado->create();
                $this->request->data['SoyaClienteDerivado']['user_id'] = $this->Auth->user('id');
                $this->request->data['SoyaClienteDerivado']['razonsocial'] = strtoupper($this->request->data['SoyaClienteDerivado']['razonsocial']);
                $this->request->data['SoyaClienteDerivado']['nombre_com'] = strtoupper($this->request->data['SoyaClienteDerivado']['nombre_com']);
            if ($this->SoyaClienteDerivado->saveAll($this->request->data)) {
                $this->Session->setFlash(__('La informacion fue guardada.'));
                return $this->redirect(array('action' => 'index'));
                }
            }

    }

1 个答案:

答案 0 :(得分:0)

问题在于你的ajax和img url。诀窍是在第一次斜杠

之前添加到..

试试这个 -

$("document").ready(
function() {
    $('#PostRubroId').bind('click', function()
    {
        $.ajax({
               type: "GET",
               url: "../soyasubrubros/getByRubro/"+$(this).val(),
               beforeSend: function() {
                     $('#PostSubrubroId').html('<div class="rating-flash" id="cargando_div">Cargando  <img src="../img/ajax-loader_mini.gif"></div>');
                     },
               success: function(msg){
                   $('#PostSubrubroId').html(msg);
               }
             });
    });
}
);
</script>