【问题标题】:Dynamic Dependent Selectbox Using Ajax jQuery cakephp使用 Ajax jQuery cakephp 的动态依赖选择框
【发布时间】:2014-04-04 21:12:28
【问题描述】:

您好,我正在尝试在 cakephp 中进行选择动态,并且我正在使用 postgres 出现此错误

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,我想要发送他的控制器,然后从那里发送子类别列表,我添加了它。 添加.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'));
                }
            }

    }

【问题讨论】:

    标签: php jquery ajax cakephp


    【解决方案1】:

    问题出在您的 ajax 和 img 网址上。诀窍是在第一个斜线之前添加到..

    试试这个-

    $("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>
    

    【讨论】:

      猜你喜欢
      • 2016-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 2013-05-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      相关资源
      最近更新 更多