How to receive data variables that are strings

How to receive data variables that are strings

TobyDSTobyDS Posts: 8Questions: 4Answers: 0

Hi, I have a table that retrieves data from an ajax page and I'm trying to pass data from some dropdowns at the same time as the ajax request however I can only receive integers.
This is my ajax code in index.php

"ajax":{
  url:"ajax2.php",
  type:"post",
  "data": function ( d ) {
  d.filter_year = $('#filter_year').val();
},
  dataType: 'json',
},

which I change to

"ajax":{
  url:"ajax2.php",
  type:"post",
  "data": function ( d ) {
  d.filter_sex = $('#filter_sex').val();
},
  dataType: 'json',
},

In ajax2.php I then change

$Year = intval($_REQUEST['filter_year']);

to

$Sex = strval($_REQUEST['filter_sex']);

If I then change filter-year to filter_sex which has a value of 'M' or 'F' It doesn't work and I get the error 'DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1'

What am I doing wrong?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,209Questions: 1Answers: 2,592
    Answer ✓

    Hi @TobyDS ,

    At a glance, everything looks OK . Did you follow the help instructions in the link in the error message? That will give some clues - especially if you look at the format/content of that JSON response.

    Cheers,

    Colin

  • TobyDSTobyDS Posts: 8Questions: 4Answers: 0

    Hi @colin,

    The problem was that livereload was causing some issues with the JSON response. Probably some clash somewhere. Anyway, it worked when I removed the link to live reload.

    Thanks for the help,
    Toby

This discussion has been closed.