Skip to main content
Known Participant
May 5, 2014
Question

Ajax call method which return json Data

  • May 5, 2014
  • 1 reply
  • 1825 views

Hi, I make one function , which i want to return json value , for this which return type i mention in function:

This is javascript which call Retrieve method.

<script>

debugger;

         var remoteDatasource = new kendo.data.DataSource({

             transport: {

                 read: {

  type:"POST",

  url: "Controllers/Home.cfc",

  dataType: "json",

                     data: {

  method: "Retrieve",

                         dataLists: JSON.stringify(request)

                     }

                 }

             },

</script>

Home.cfc

component

{

remote   function Retrieve(string dataLists)

  {

  try

  {

            q = new Query();

            q.setsql("SELECT * FROM Product");

            qResult = q.execute().getresult();

            col_len = ListLen(qResult.Columnlist);

            dataArray = ArrayNew(1);

            row = 0;

            col = 0;

            for(row = 1; row <= len; row++)

            {

                 for(col = 1; col <= col_len; col++)

                 {

                      FieldName = ListGetAt(qResult.Columnlist, col);

                      dataArray[row][col] = qResult[FieldName][col];

                 }

            }

      jsonvar=serializeJSON(dataArray);

  }

  catch(any e)

  {

  }

return jsonvar;

  }

}

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    May 5, 2014

    One can see immediately that you have to make the following corrections, at least:

    1. Give the query a name;
    2. Point the query to a datasource;
    3. Define the variable 'len' (even better, use a different, less confusing, name for the variable).
    Known Participant
    May 6, 2014

    ok i done the change...