Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82033

json returns nothing after value changed

$
0
0

Hi guys, I have DataTables table with row details which are opening by clicking on row. The row details are displayed in 3 different languages which are selected by checkbox. When the row is clicked, the language is send to details.php script (langy:chLanguage) which returns json values for this selected language.

Initialy the language is set to chDe and everything is working fine until I click on another language. When the language is changed to EN or RU, or even back to DE, the returned json is empty.

Index.php:

<h5>Language</h5>

  <input type="checkbox" id="chDe" name="languages" checked>DE
  <input type="checkbox" id="chEn" name="languages">EN
  <input type="checkbox" id="chRu" name="languages">RU

<script>

var chLanguage = "chDe";
$('input[name=languages]').click(function() {
        $('input[name="' + this.name + '"]').not(this).prop('checked', false);
        chLanguage = [];
        $('input[name=languages]:checked').each(function() {
                chLanguage.push($(this).attr('id'));
        });
        if (chLanguage == '') {
                chLanguage = 5;
        }
        $('#example').DataTable().ajax.reload();
});


function format ( rowData, row, $chLanguage ) {
// FOLLOWING CONSOLE.LOG RETURNS THE ACTUALLY SELECTED LANGUAGE CORRECTLY
        console.log("chLanguage in format function: " + chLanguage);
    var div = $('<div/>')
        .addClass( 'loading slider' )
    $.ajax( {
        url: 'scripts/details.php',
        data: {
            name: rowData[0],
            langy: chLanguage,
        },
        dataType: 'json',
        type: 'post',
        success: function ( json ) {
// FOLLOWING CONSOLE.LOG RETURNS [Object object] unless the language is changed, then it returns nothing
            console.log("json: " + json);
            var childTable = '<div id="rowdetails" class="slidera"><ul class="slider">';
            childTable = childTable.concat(
                '<div class="row rdstyle">' +
                   '<table class="detailstable detailserrors">' +
                      '<tr><td><b>Error class:</b></td><td>' + json[0].ERRTRIEDA + '</td></tr>' +
                      '<tr><td><b>Error group:</b></td><td>' + json[0].ERRSKUPINA + '</td></tr>' +
                      '<tr><td><b>Error:</b></td><td>' + json[0].ERRPOPIS + '</td></tr>' +
                    '</table>' +
                '</div>
  );
 });
}

details.php:

$language = $_POST['langy'];

if ($language == 'chDe' ) {
        $setLang = 'DE';
}else if($language == 'chEn') {
        $setLang = 'EN';
} else{$setLang = 'RU';}

and $setLang is used in SQL query to filter data by language.

I hope I'm not far away from working solution, because it's working already, just the language switch don't work. Sorry not to attach working sample. I don't know how to implement all these parts including mysql db and several differenct php scripts :(
Thank you.


Viewing all articles
Browse latest Browse all 82033

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>