Welcome Guest, Not a member yet? Register   Sign In
Can't load controller function, codeigniter 3.x
#1

I'm having some issues trying to load a function from a JS in a view page. It works with others view page, but for some reason this one called sistemas_aplicaciones doesn't work, it can't find the controller in order to show the view page.

This is the submenu view that calls the function in controller.


Code:
    <?php
    defined("BASEPATH") OR exit("No direct script access allowed");
    ?>
    <script type="text/javascript" src="<?php echo base_url('assets/js/helper/func_administracion.js');?>"></script>
         <ul class="nav nav-stacked" id="accordion" role="tablist" aria-multiselectable="true">
                    <input type="hidden" id="id_menu_superior" value="{id_menu_superior}"/>
                    <input type="hidden" id="vista" value="{vista}"/>
        <li  class="active" id="0" role="tab" >
                        <a href="<?= base_url('{vista}/load_default_content')?>" id="call_default">
            <span><?= img(base_url("assets/img/ico12_treeleaf.gif"),FALSE)?> </span>
                 Acerca del M&oacute;dulo  {menu_superior}
            </a>  
                    </li>
        {submenu}
                    <li class="panel" id="{id_menu}" >      
          <a role="button" data-toggle="collapse" data-parent="#accordion" 
            href="#submenu_{id_menu}" aria-expanded="true" aria-controls="submenu_{id_menu}">
            <?= img(base_url("assets/img/1x1.gif"),FALSE,array("id"=>"folder_{id_menu}","class"=>"plus"))?>
            <?= img(base_url("assets/img/ico12_treefolder.gif"),FALSE)?> 
               {nombre}  
              </a>    
          <ul id="submenu_{id_menu}" class="nav collapse" role="tabpanel" aria-labelledby="{id_menu}">
      <li style="padding-left: 15px;">
      <!-- Here is where you call the controller function -->
          <a href="<?= base_url('{vista}/create')?>"  name="sub_m_{id_menu}_create" id="sub_m_{id_menu}_create" >
              <span><?= img(base_url("assets/img/ico12_treeleaf.gif"),FALSE)?> </span> 
              Agregar 
              </a>
          </li>
            <li style="padding-left: 15px;">
          <a href="<?= base_url('{vista}/search')?>"  name="sub_m_{id_menu}_search" id="sub_m_{id_menu}_search">
              <span><?= img(base_url("assets/img/ico12_treeleaf.gif"),FALSE)?> </span> 
              Consultar 
              </a>
            </li>
      </ul> 
  </li>
  {/submenu}
    </ul>


This view page will generate some buttons based on the id_menu loaded from a database called menu. when you click the agregar button it will execute a JS that will take the href and enter in the controller function create.

 
Code:
      $("ul.nav.collapse a").on("click", function(){
            $.ajax({
                type: 'POST',
                url: $(this).attr("href"),
                data: {},
                dataType: 'json',
                // Mostramos un mensaje con la respuesta de PHP
                success: function(data) {
                        $('#principal').html(data.mensaje);
                },
                error: function(error){
                    $('#principal').html('<div class="alert alert-warning alert-dismissible" role="alert">'+
                        '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+
                        '<strong>Error!!!</strong> Solicitud de AJAX no completada->'+error.status+'</div>'); 
                }              
            }) ;
                return false;
        });
        
    });


The function will return an array of the view page of sistemas_aplicaciones and show it in the #principal tag. 

Like I said, this is working for the other controllers and view page in my project, but for sistemas_aplicaciones doesn't work, its showing an ajax error 404 not found. Can someone help me to understand why?
Reply
#2

I cannot see the link you are referring to in the code you posted, but if you are getting the error 404 for a JS ajax call the first thing to do is output the link you think you are using, to check it. The link is probably malformed.

If it is, either there is an error in your JS in creating the link or the data you are referring to in order to get the link is not being set in the way you thought it was. Either way, it is just a case of tracking back to find where the error is actually occurring, which in the case of a 404, should be relatively easy to do.
Reply
#3

Sorry, the href i'm using it has the same structure used by the others controllers, the only difference is the name. for example:

http://[ip]/CatalogoPIC250216/verticales/create
http://[ip]/CatalogoPIC250216/sistemas_aplicaciones/create
Reply
#4

What do get i you use the url directly ?
As the error seams to be with this controller only, the bug is more than likely in the create method.
A good decision is based on knowledge and not on numbers. - Plato

Reply
#5

Yes... it was the controller... the 

Code:
class Sistemas_aplicaciones mextends CI_Controller

wasn't writed well. Now it works out.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB