Welcome Guest, Not a member yet? Register   Sign In
Jquery ajax success null response on production server
#1

[eluser]Paul Hernández[/eluser]
Hi:

I'm developing an app. using ci2. Everything work fine in my development server (apache2, ubuntu 9, mysql). Today I uploaded the code to the production server and the ajax calls do not work anymore. It could be an Apache configuration issue?

Here is the js:
Code:
// Loading jornadas editions
    $( function() {
    var listados    = 'index.php/listados/index',
        dataTable,
        dataTableOptions = {"bJQueryUI": true};

    $( '#tabs' ).tabs({
        fx: {height: 'toggle', opacity: 'toggle'}
    });

    $.ajax({
        type: 'POST',
        url: 'index.php/home/loadJornadasEditions',
        dataType: 'json',
        async: true,
        success: function( response ) {
        //[removed] (response);
        if (response == null){
            //[removed] (response);
        }
        else{
        for( var i in response ) {
            response[ i ].urlLink = 'index.php/form/url' + '/' + response[ i ].formulario_id;
            response[ i ].listadosLink = 'index.php/listados/listados_jornada/'+ response[ i ].edicion_jornada_id;
        }
            //clear old rows (if any)
            $('#eJornadas tbody').html('');
            //convert json string returned from server into native array of javascript objects
            $( '#readTemplate2' ).render( response ).appendTo( "#eJornadas tbody" );
            //apply dataTable to #records table and save its object in dataTable variable
            //$( '#readTemplate' ).render( response ).appendTo( "#records" );
             dataTable = $( '#eJornadas' ).dataTable(dataTableOptions);
            //hide ajax loader animation here...
            $( '#ajaxLoadAni' ).fadeOut( 'slow' );
        
        }
        
        }
    });

    //Listados button
    $( "#eJornadas" ).delegate( "a.listadosBtn", "click", function() {
     formHref = $( this ).attr( 'href' );
    [removed].href = $( this ).attr( 'href' );

    }); //end delegate

    //Form load button. Load the form of the selected jornada edition
    $( "#eJornadas" ).delegate( "a.urlBtn", "click", function() {
    // formHref = $( this ).attr( 'href' );
    [removed].href = $( this ).attr( 'href' );

    }); //end delegate
});

The code above make a query to the database that return some info to be place in a table ('#eJornadas').

This is the code of the view:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
&lt;html&gt;
&lt;head&gt;
    &lt;meta content="text/html; charset=UTF-8"/&gt;
&lt;title&gt;Ediciones de Jornada&lt;/title&gt;

&lt;base href="&lt;?php echo base_url(); ?&gt;" /&gt;

&lt;link type="text/css" rel="stylesheet" href="css/smoothness/jquery-ui-1.8.2.custom.css" /&gt;
&lt;link type="text/css" rel="stylesheet" href="css/styles.css" /&gt;
&lt;!-- [removed][removed] --&gt;

&lt;/head&gt;
&lt;body&gt;

    <div class="message">&lt;?php
       // if($message!=""){
            //echo $message;
            echo $this->session->flashdata('message');
        //}

            ?&gt;
</div>
    <br/>
    
<div id="tabs">
    <ul>
        <li><a href="#edicionesJornadas">Ediciones jornadas</a>
    </ul>
&lt;!-- Edición de jornadas tab --&gt;
<div id="edicionesJornadas">
     <table id="eJornadas" class="records">
        <thead>
            <tr>
                <th class="rowNumber">Nº</th>
                <th class="nj">Nombre de la Jornada</th>
                <th>Edición</th>
                <th>Lugar</th>
                <th class="fecha">Fecha de inicio</th>
                <th class="fecha">Fecha de finalización</th>
                <th class="accion">Acción</th>
            </tr>
        </thead>
        <tbody></tbody>

        </table>
        <br/>
        
    </div>

</div>


[removed][removed]
[removed][removed]
[removed][removed]
[removed][removed]
[removed][removed]

[removed]
  <tr id="${edicion_jornada_id}">
        <td>${edicion_jornada_id}</td>
        <td>${jornada_id}</td>
        <td>${edicion_jornada_nombre}</td>
        <td>${pais_id}</td>
        <td>${edicion_jornada_fecha_inicio}</td>
        <td>${edicion_jornada_fecha_finalizacion}</td>
        <td><a class="listadosBtn" href="${listadosLink}">Listados</a> | <a class="urlBtn" href="${urlLink}">URL</a>
        </td>
        </tr>
[removed]
[removed][removed]
&lt;/body&gt;
&lt;/html&gt;
And the controller (only the function that is called from ajax):
Code:
public function loadJornadasEditions(){
           echo json_encode($this->ej->getJornadasEditions());
And the model (just in case)
Code:
public function getJornadasEditions(){
         //get all records from edicionesjornadas table
        $this->db->select('ej.edicion_jornada_id, ej.jornada_id, ej.edicion_jornada_nombre, ej.pais_id,
            ej.edicion_jornada_fecha_inicio, ej.edicion_jornada_fecha_finalizacion, form.formulario_id');
        $this->db->from('ediciones_jornadas AS ej');
        $this->db->join('formularios AS form', 'form.edicion_jornada_id = ej.edicion_jornada_id', 'left');
        $query = $this->db->get();

        if( $query->num_rows() > 0 ) {
            return $query->result();
Importance things to notice:
- The response value is null.
- The script is called at the end of the view after de table template
- It works in my local server (on my computer)

Thanks for your help
#2

[eluser]Paul Hernández[/eluser]
Ok, after 4 days of pain I found the problem.
It seems to be simple but for me was very difficult.

The root of the problem is the PHP version of the production server (5.1.6)

The ajax method that retrieve the data to populate the tables uses the php function "json_encode". This function is available for php versions > 5.2

I'm also using the jquery template plugin, and the method "render" which render the tables uses json data format and no other.

In my case update the php version of the server is not so simple as is a third party production server, so I found a library to give json support to previous php version:
http://www.boutell.com/scripts/jsonwrapper.html

I also recommend this series of tutorials about CRUD app. CI and jquery:
http://www.ifadey.com/2010/06/crud-using...deigniter/

Enjoy it!




Theme © iAndrew 2016 - Forum software by © MyBB